I'm looking for a way to initialize a FastAPI server with an existing OpenAPI YAML schema file.
The docs do describe how to modify the auto-generated schema, but I'm looking for something like Connexion, which can generate the validators on-the-fly.
I've traced down the offending property to this one:
class MyParameters(BaseModel):
...
ModelName: Optional[ModelName] = Field(None, description='')
...
The matching object schema in openapi.yaml:
MyParameters:
type: object
properties:
...
ModelName:
type: string
enum: [XYZ]
description: ""
...
ModelName is not mandatory.
After resolving the issue with fastapi-code-generator, I've opted to use it.
For future readers, who use Python 3.7, the issue was a missing import in the generated models.py file:
from __future__ import annotations
Adding it at the top of models.py resolved the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With