-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openapi.json throws error when generated with nested models #3782
Comments
Reposting my response from the closed issue that yeus linked to so it doesn't go overlooked: I have similar code structure to @yeus and also am running into this issue. I only have issues with This code will generate proper documentation when using # Obviously skipping some imports
class DataResponse(BaseModel):
data: typing.List[int]
limits: typing.List[typing.Tuple[float,float]]
counts: typing.Tuple[int,int]
@app.post("/bins",
status_code=status.HTTP_200_OK,
tags=["data"],
response_model=DataResponse)
def bins(input: DataSelection):
return None
if __name__ == "__main__":
import uvicorn
uvicorn.run("server:app", host="127.0.0.1", port=8001, log_level="info") When the above is run using When the above is run using File "pydantic\main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 3 validation errors for OpenAPI
components -> schemas -> DataResponse -> properties -> limits -> items -> items
value is not a valid dict (type=type_error.dict)
components -> schemas -> DataResponse -> properties -> counts -> items
value is not a valid dict (type=type_error.dict)
components -> schemas -> DataResponse -> $ref
field required (type=value_error.missing) For now, I am just downgrading fastapi so that documentation works. |
I should note that I also tested on both Windows and Linux, and I get the same results regardless of OS. |
Hitting the same issue, here is a reproducible example from typing import List, Tuple
from fastapi import FastAPI
from pydantic import BaseModel
class GeoJson2DPoint(BaseModel):
type: str = "Point"
coordinates: Tuple[float, float] = (0.0, 0.0)
class Address(BaseModel):
street_number: int
street_name: str
city: str
country: str
geo: GeoJson2DPoint
postal_code: str
app = FastAPI()
@app.get("/places", response_model=List[Address])
async def get_addresses() -> List[Address]:
... |
Try to change |
Yes, If you comment out the coordinates field, or change the type to a non-collection, the error goes away |
I can also verify that commenting out the coordinates field, or changing to a plain iterator (i.e. This is clearly a bug that was introduced between |
I reckon its this change 97fa743 |
@tonybaloney @yeus this seems to be related to #3665 (possibly a duplicate?) |
@HansBrende This definitely appears to be a duplicate. I had seen this error in a previous duplicate, but it looked like it had been fixed, and then reintroduced again. |
It seems this is a duplicate of #3665 In short, it should be fixed by FastAPI For more info, read the last comment in that issue: #3665 (comment) And the comment in the PR: #3874 (comment) |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
First Check
Commit to Help
Example Code
Description
open http://localhost:5000/docs or http://localhost:5000/openapi.json and you will see the error in the logs.
Operating System
Linux
Operating System Details
ubuntu 20.04
FastAPI Version
0.68.1
Python Version
3.8.10
Additional Context
There was a bug #383 a while ago reporting the same problem but closed. This new issue here is in order to reopen that bug as it still isn't solved or reappeared since then. Fell free to close this new issue and reopen the old bug if that is preferred.
this is the error:
The text was updated successfully, but these errors were encountered: