-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
from pydantic import BaseModel
from fastapi import Request
class ResponseInfo(BaseModel):
status: str | None = None
entry_id: int
app = FastAPI()
@app.post("/info", response_model=ResponseInfo)
async def read_item(request: Request):
return ResponseInfo(entry_id=10) DescriptionAfter running server i expect to see response model to have optional status, but swagger show it as required. I checked This takes place only in response_model; in request works as expected Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.101.0 Pydantic Version2.1.1 Python Version3.11.0 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Seeing the same issue. This will cause problems with response deserialization if you generate a client from this spec in a language such as C#. Pydantic 2.1.1, FastAPI 0.101.0. |
Beta Was this translation helpful? Give feedback.
-
It generates |
Beta Was this translation helpful? Give feedback.
-
Yep, there was a lot of work put to get this new behavior, it's actually more correct, but I just added a feature to allow disabling it if you want to get the old behavior back, it's available since FastAPI 0.102.0 🎉 https://fastapi.tiangolo.com/how-to/separate-openapi-schemas/ |
Beta Was this translation helpful? Give feedback.
Yep, there was a lot of work put to get this new behavior, it's actually more correct, but I just added a feature to allow disabling it if you want to get the old behavior back, it's available since FastAPI 0.102.0 🎉 https://fastapi.tiangolo.com/how-to/separate-openapi-schemas/