When converting a Python function into a FastAPI route using our tool, if the function parameters are not typed, the generated Pydantic model uses the type Any. This results in the generated code being void and can lead to runtime errors or validation issues.
Steps to Reproduce:
Create a function with untyped parameters, for example:
def foo(bar=None, baz=None):
pass
Use the tool to generate the FastAPI route.
Observe that the generated Pydantic model is as follows:
class Foo_model(BaseModel):
bar: Any
baz: Any
Expected Behavior:
The tool should either throw an error when encountering untyped function parameters or handle such parameters in a way that doesn't use the type Any.
Observed Behavior:
The tool generates a model using the type Any, which can lead to runtime errors or validation issues.
Note:
If the function is typed, as in the following example:
def foo(bar:str=None, baz:str=None):
pass
The tool correctly generates the model as:
class Foo_model(BaseModel):
bar: str
baz: str
Proposed Solution:
Add validation to check if function parameters are typed.
Throw an appropriate error if parameters are untyped.
Alternatively, the tool could try to infer the type from the default parameter value or use a more generic type than Any.
You can use this ticket as a base and adapt it according to your bug-tracking system or project specifics.
Description:
When converting a Python function into a FastAPI route using our tool, if the function parameters are not typed, the generated Pydantic model uses the type
Any
. This results in the generated code being void and can lead to runtime errors or validation issues.Steps to Reproduce:
Expected Behavior:
The tool should either throw an error when encountering untyped function parameters or handle such parameters in a way that doesn't use the type
Any
.Observed Behavior:
The tool generates a model using the type
Any
, which can lead to runtime errors or validation issues.Note:
If the function is typed, as in the following example:
The tool correctly generates the model as:
Proposed Solution:
Any
.You can use this ticket as a base and adapt it according to your bug-tracking system or project specifics.