mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-14 17:08:06 -05:00
📝 Document additional parameters for response_model (#1427)
* Documented additional parameters These are included in a recent PR (https://github.com/tiangolo/fastapi/pull/1166) but not in the docs yet. * response_model_exclude_none * response_model_exclude_defaults * 📝 Update note about response_model_exclude_defaults and response_model_exclude_none Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@@ -124,6 +124,14 @@ So, if you send a request to that *path operation* for the item with ID `foo`, t
|
||||
!!! info
|
||||
FastAPI uses Pydantic model's `.dict()` with <a href="https://pydantic-docs.helpmanual.io/usage/exporting_models/#modeldict" class="external-link" target="_blank">its `exclude_unset` parameter</a> to achieve this.
|
||||
|
||||
!!! info
|
||||
You can also use:
|
||||
|
||||
* `response_model_exclude_defaults=True`
|
||||
* `response_model_exclude_none=True`
|
||||
|
||||
as described in <a href="https://pydantic-docs.helpmanual.io/usage/exporting_models/#modeldict" class="external-link" target="_blank">the Pydantic docs</a> for `exclude_defaults` and `exclude_none`.
|
||||
|
||||
#### Data with values for fields with defaults
|
||||
|
||||
But if your data has values for the model's fields with default values, like the item with ID `bar`:
|
||||
|
||||
Reference in New Issue
Block a user