koxudaxi / fastapi-code-generator

This code generator creates FastAPI app from an openapi file.
MIT License
1.08k stars 109 forks source link

Parameter schema is None errors when parsing OpenAPI 2.0 JSON specification #453

Closed joshuaboniface closed 1 month ago

joshuaboniface commented 1 month ago

I have an OpenAPI 2.0 specification generated with Flask-Swagger, i.e. it has swagger: "2.0".

Trying to run fastapi-code-generator on this, I get errors like this for all of my parameters:

│ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────── locals ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮   │
│ │  data_type = None                                                                                                                                                                                                                     │   │
│ │       name = 'sort_key'                                                                                                                                                                                                               │   │
│ │  orig_name = 'sort_key'                                                                                                                                                                                                               │   │
│ │ parameters = ParameterObject(name='sort_key', in_=<ParameterLocation.query: 'query'>, description='The fault object key to sort results by', required=False, deprecated=False, schema_=None, example=None, examples=None, content={}) │   │
│ │       path = ['#/paths', 'api/v1/faults', 'get', 'parameters']                                                                                                                                                                        │   │
│ │     schema = None                                                                                                                                                                                                                     │   │
│ │       self = <fastapi_code_generator.parser.OpenAPIParser object at 0x7fb59febc8d0>                                                                                                                                                   │   │
│ │ snake_case = False                                                                                                                                                                                                                    │   │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯   │
╰──────────────────────────────
RuntimeError: schema is None

Which is expected: OpenAPI 2.0 does not have the concept of a schema for parameters, only a type directly.

Is this supported somehow?

joshuaboniface commented 1 month ago

I ended up rebuilding my API specification as OpenAPI 3.0 and this worked, so I suspect this just isn't supported. Closing out to avoid clutter, but I would suggest adding this to the docs.