Docs: clarify runtime vs OpenAPI behavior of responses model

This commit is contained in:
champ-sk 2026-01-05 18:29:26 +05:30
parent f2687dc1bb
commit 3d67642b99
1 changed files with 10 additions and 0 deletions

View File

@ -22,6 +22,16 @@ It receives a `dict`: the keys are status codes for each response (like `200`),
Each of those response `dict`s can have a key `model`, containing a Pydantic model, just like `response_model`.
/// note
The `model` key inside `responses` is used **only for OpenAPI
documentation generation**.
It does **not** perform runtime response validation or filtering.
If you want FastAPI to validate and filter the returned data at
runtime, use `response_model` instead.
///
**FastAPI** will take that model, generate its JSON Schema and include it in the correct place in OpenAPI.
For example, to declare another response with a status code `404` and a Pydantic model `Message`, you can write: