You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2f6d43c
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/cookie-param-models.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,16 @@ You can combine multiple cookie parameter models with individual cookie paramete
77
77
78
78
Parameters declared elsewhere in the same operation or its dependencies are not treated as extra fields of a model. Undeclared cookie parameters still follow the model's `extra` configuration.
If neither `theme` nor `locale` is sent, `preferences` is `None`. If either is sent, FastAPI validates the model and requires both fields.
87
+
88
+
The same rules for defaults, extra fields, and OpenAPI apply as for [optional query parameter models](query-param-models.md#optional-query-parameter-models).
89
+
80
90
## Summary { #summary }
81
91
82
92
You can use **Pydantic models** to declare <dfntitle="Have a last cookie before you go. 🍪">**cookies**</dfn> in **FastAPI**. 😎
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/header-param-models.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,18 @@ Parameters declared elsewhere in the same operation or its dependencies are not
75
75
76
76
Each model uses its own `Header(convert_underscores=...)` setting, both when reading the request and when generating OpenAPI. Explicit field aliases remain literal header names.
If neither `x-client-name` nor `x-client-version` is sent, `client` is `None`. If either is sent, FastAPI validates the model and requires both fields.
85
+
86
+
The same rules for defaults, extra fields, and OpenAPI apply as for [optional query parameter models](query-param-models.md#optional-query-parameter-models).
87
+
88
+
Headers such as `Host` also follow the model's `extra` configuration. With `extra="allow"`, they make the model present even if neither declared field is supplied.
89
+
78
90
## Summary { #summary }
79
91
80
92
You can use **Pydantic models** to declare **headers** in **FastAPI**. 😎
If neither `start` nor `end` is sent, `date_range` is `None`. If either is sent, FastAPI validates the model and requires both fields.
87
+
88
+
Using `| None` without a default still makes the parameter required.
89
+
90
+
Unknown parameters follow the model's `extra` configuration. Ignored extras do not make the model present.
91
+
92
+
OpenAPI lists the group's fields individually and marks them as optional.
93
+
94
+
You can also declare optional [header parameter models](header-param-models.md#optional-header-parameter-models) and [cookie parameter models](cookie-param-models.md#optional-cookie-parameter-models).
95
+
80
96
## Summary { #summary }
81
97
82
98
You can use **Pydantic models** to declare **query parameters** in **FastAPI**. 😎
0 commit comments