[BUG] openapi.json fails to be generated for nested models
See original GitHub issueDescribe the bug Fails to autogenerate docs.
To Reproduce
- Create a response model with other nested models and try to generate openapi.json or open autogenerated docs.
- Application throws an error
Expected behavior Generate openapi.json and open autogenerated docs without problems.
Environment:
- OS: macOS
- FastAPI Version: 0.30.0
- Python version: 3.7.3
Additional context
My models look like this:
class PaginatedItems(Generic[Item], BaseModel, abc.ABC):
items: List[Any]
has_after: bool = False
has_before: bool = False
class OrderUser(BaseModel):
name: Optional[str] = None
email: EmailStr
class Order(BaseModel):
order_id: UUID
amount: Decimal
currency: str
# Users part
merchants: List[OrderUser]
handlers: List[OrderUser]
class PaginatedOrders(PaginatedItems[Order]):
items: List[Order] = list()
My route definition looks like that:
@router.get(orders_uri,
response_model=PaginatedOrders
async def list():
...
This results in the following exception when trying to open autogenerated docs:
pydantic.error_wrappers.ValidationError: 4 validation errors
schemas -> OrderUser
value is not a valid dict (type=type_error.dict)
schemas -> OrderUser
value is not a valid dict (type=type_error.dict)
components -> schemas
value is not none (type=type_error.none.allowed)
components
value is not none (type=type_error.none.allowed)
When I comment out the response_model=PaginatedOrders
part from route definition everything works, but docs obviously miss response type.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
OpenApi required property in nested objects not working
I need to describe an api having in request body an object with required fields and one of these fields it's an object...
Read more >Usage - OpenAPI Generator
The batch command allows you to move all CLI arguments supported by the generate command into a YAML or JSON file. NOTE: This...
Read more >Unrecognized field, not marked as ignorable - JSON Parsing ...
This error was occurring because my nested class Person was not static, which means it cannot be instantiated because of having any Outer...
Read more >Additional Responses in OpenAPI - FastAPI - tiangolo
FastAPI will take that model, generate its JSON Schema and include it in the correct place in OpenAPI. For example, to declare another...
Read more >Components Section - Swagger
OAS 3 This guide is for OpenAPI 3.0. ... description: An error occurred. content: application/json: schema: $ref: '#/components/schemas/Error' ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
oups sorry I think your mistake is putting
response_model=SimilarProducts,
in the wrong spot, it’s in the @router partI can confirm it now works fine! Thanks for fixing it so quickly!