@@ -8,57 +8,9 @@ First, of course, you can mix `Path`, `Query` and request body parameter declara
88
99And you can also declare body parameters as optional, by setting the default to ` None ` :
1010
11- //// tab | Python 3.10+
11+ { * ../../docs_src/body_multiple_params/tutorial001_an_py310.py hl [ 18:20 ] * }
1212
13- ``` Python hl_lines="18-20"
14- {!> ../ ../ docs_src/ body_multiple_params/ tutorial001_an_py310.py!}
15- ```
16-
17- ////
18-
19- //// tab | Python 3.9+
20-
21- ``` Python hl_lines="18-20"
22- {!> ../ ../ docs_src/ body_multiple_params/ tutorial001_an_py39.py!}
23- ```
24-
25- ////
26-
27- //// tab | Python 3.8+
28-
29- ``` Python hl_lines="19-21"
30- {!> ../ ../ docs_src/ body_multiple_params/ tutorial001_an.py!}
31- ```
32-
33- ////
34-
35- //// tab | Python 3.10+ non-Annotated
36-
37- /// tip
38-
39- Prefer to use the ` Annotated ` version if possible.
40-
41- ///
42-
43- ``` Python hl_lines="17-19"
44- {!> ../ ../ docs_src/ body_multiple_params/ tutorial001_py310.py!}
45- ```
46-
47- ////
48-
49- //// tab | Python 3.8+ non-Annotated
50-
51- /// tip
52-
53- Prefer to use the ` Annotated ` version if possible.
54-
55- ///
56-
57- ``` Python hl_lines="19-21"
58- {!> ../ ../ docs_src/ body_multiple_params/ tutorial001.py!}
59- ```
60-
61- ////
13+ ## Multiple body parameters
6214
6315/// note
6416
@@ -81,21 +33,8 @@ In the previous example, the *path operations* would expect a JSON body with the
8133
8234But you can also declare multiple body parameters, e.g. ` item ` and ` user ` :
8335
84- //// tab | Python 3.10+
85-
86- ``` Python hl_lines="20"
87- {!> ../ ../ docs_src/ body_multiple_params/ tutorial002_py310.py!}
88- ```
89-
90- ////
36+ {* ../../docs_src/body_multiple_params/tutorial002_py310.py hl[ 20] * }
9137
92- //// tab | Python 3.8+
93-
94- ``` Python hl_lines="22"
95- {!> ../ ../ docs_src/ body_multiple_params/ tutorial002.py!}
96- ```
97-
98- ////
9938
10039In this case, ** FastAPI** will notice that there is more than one body parameter in the function (there are two parameters that are Pydantic models).
10140
@@ -136,57 +75,8 @@ If you declare it as is, because it is a singular value, **FastAPI** will assume
13675
13776But you can instruct ** FastAPI** to treat it as another body key using ` Body ` :
13877
139- //// tab | Python 3.10+
140-
141- ``` Python hl_lines="23"
142- {!> ../ ../ docs_src/ body_multiple_params/ tutorial003_an_py310.py!}
143- ```
144-
145- ////
146-
147- //// tab | Python 3.9+
148-
149- ``` Python hl_lines="23"
150- {!> ../ ../ docs_src/ body_multiple_params/ tutorial003_an_py39.py!}
151- ```
152-
153- ////
154-
155- //// tab | Python 3.8+
156-
157- ``` Python hl_lines="24"
158- {!> ../ ../ docs_src/ body_multiple_params/ tutorial003_an.py!}
159- ```
160-
161- ////
162-
163- //// tab | Python 3.10+ non-Annotated
164-
165- /// tip
166-
167- Prefer to use the ` Annotated ` version if possible.
168-
169- ///
78+ {* ../../docs_src/body_multiple_params/tutorial003_py310.py hl[ 23] * }
17079
171- ``` Python hl_lines="20"
172- {!> ../ ../ docs_src/ body_multiple_params/ tutorial003_py310.py!}
173- ```
174-
175- ////
176-
177- //// tab | Python 3.8+ non-Annotated
178-
179- /// tip
180-
181- Prefer to use the ` Annotated ` version if possible.
182-
183- ///
184-
185- ``` Python hl_lines="22"
186- {!> ../ ../ docs_src/ body_multiple_params/ tutorial003.py!}
187- ```
188-
189- ////
19080
19181In this case, ** FastAPI** will expect a body like:
19282
@@ -226,57 +116,8 @@ q: str | None = None
226116
227117For example:
228118
229- //// tab | Python 3.10+
230-
231- ``` Python hl_lines="28"
232- {!> ../ ../ docs_src/ body_multiple_params/ tutorial004_an_py310.py!}
233- ```
234-
235- ////
236-
237- //// tab | Python 3.9+
238-
239- ``` Python hl_lines="28"
240- {!> ../ ../ docs_src/ body_multiple_params/ tutorial004_an_py39.py!}
241- ```
242-
243- ////
244-
245- //// tab | Python 3.8+
246-
247- ``` Python hl_lines="29"
248- {!> ../ ../ docs_src/ body_multiple_params/ tutorial004_an.py!}
249- ```
250-
251- ////
119+ {* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[ 28] * }
252120
253- //// tab | Python 3.10+ non-Annotated
254-
255- /// tip
256-
257- Prefer to use the ` Annotated ` version if possible.
258-
259- ///
260-
261- ``` Python hl_lines="26"
262- {!> ../ ../ docs_src/ body_multiple_params/ tutorial004_py310.py!}
263- ```
264-
265- ////
266-
267- //// tab | Python 3.8+ non-Annotated
268-
269- /// tip
270-
271- Prefer to use the ` Annotated ` version if possible.
272-
273- ///
274-
275- ``` Python hl_lines="28"
276- {!> ../ ../ docs_src/ body_multiple_params/ tutorial004.py!}
277- ```
278-
279- ////
280121
281122/// info
282123
@@ -298,57 +139,8 @@ item: Item = Body(embed=True)
298139
299140as in:
300141
301- //// tab | Python 3.10+
302-
303- ``` Python hl_lines="17"
304- {!> ../ ../ docs_src/ body_multiple_params/ tutorial005_an_py310.py!}
305- ```
306-
307- ////
308-
309- //// tab | Python 3.9+
310-
311- ``` Python hl_lines="17"
312- {!> ../ ../ docs_src/ body_multiple_params/ tutorial005_an_py39.py!}
313- ```
314-
315- ////
316-
317- //// tab | Python 3.8+
318-
319- ``` Python hl_lines="18"
320- {!> ../ ../ docs_src/ body_multiple_params/ tutorial005_an.py!}
321- ```
322-
323- ////
324-
325- //// tab | Python 3.10+ non-Annotated
326-
327- /// tip
328-
329- Prefer to use the ` Annotated ` version if possible.
330-
331- ///
332-
333- ``` Python hl_lines="15"
334- {!> ../ ../ docs_src/ body_multiple_params/ tutorial005_py310.py!}
335- ```
336-
337- ////
338-
339- //// tab | Python 3.8+ non-Annotated
340-
341- /// tip
342-
343- Prefer to use the ` Annotated ` version if possible.
344-
345- ///
346-
347- ``` Python hl_lines="17"
348- {!> ../ ../ docs_src/ body_multiple_params/ tutorial005.py!}
349- ```
142+ {* ../../docs_src/body_multiple_params/tutorial005_an_py310.py hl[ 17] * }
350143
351- ////
352144
353145In this case ** FastAPI** will expect a body like:
354146
0 commit comments