Debian Codegraph @

docs_src/schema_extra_example/tutorial004_an_py310.py

raw
1 from typing import Annotated
2
3 from fastapi import Body, FastAPI
4 from pydantic import BaseModel
5
6 app = FastAPI()
7
8
9 class Item(BaseModel):
10 name: str
11 description: str | None = None
12 price: float
13 tax: float | None = None
14
15
16 @app.put("/items/{item_id}")
17 async def update_item(
18 *,
19 item_id: int,
20 item: Annotated[
21 Item,
22 Body(
23 examples=[
24 {
25 "name": "Foo",
26 "description": "A very nice Item",
27 "price": 35.4,
28 "tax": 3.2,
29 },
30 {
31 "name": "Bar",
32 "price": "35.4",
33 },
34 {
35 "name": "Baz",
36 "price": "thirty five point four",
37 },
38 ],
39 ),
40 ],
41 ):
42 results = {"item_id": item_id, "item": item}
43 return results