Alien6-Studio / outerspace-apizr

OuterSpace APIzr
https://apizr.outerspace.sh/
3 stars 0 forks source link

[BUG] FastAPI model generation fails when function parameters are untyped #8

Closed Coopyrightdmin closed 1 year ago

Coopyrightdmin commented 1 year ago

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:

  1. Create a function with untyped parameters, for example:
    def foo(bar=None, baz=None):
    pass
  2. Use the tool to generate the FastAPI route.
  3. 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:


You can use this ticket as a base and adapt it according to your bug-tracking system or project specifics.

Coopyrightdmin commented 1 year ago

We have implemented changes to address the issue mentioned. Here's a summary of the adjustments made: