Debian Codegraph @

docs_src/body_fields/tutorial001_an_py310.py

raw
1 from typing import Annotated
2
3 from fastapi import Body, FastAPI
4 from pydantic import BaseModel, Field
5
6 app = FastAPI()
7
8
9 class Item(BaseModel):
10 name: str
11 description: str | None = Field(
12 default=None, title="The description of the item", max_length=300
13 )
14 price: float = Field(gt=0, description="The price must be greater than zero")
15 tax: float | None = None
16
17
18 @app.put("/items/{item_id}")
19 async def update_item(item_id: int, item: Annotated[Item, Body(embed=True)]):
20 results = {"item_id": item_id, "item": item}
21 return results