Coverage for docs_src/body_fields/tutorial001_py310.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1from fastapi import Body, FastAPI 1abcde
2from pydantic import BaseModel, Field 1abcde
4app = FastAPI() 1abcde
7class Item(BaseModel): 1abcde
8 name: str 1abcde
9 description: str | None = Field( 1abcde
10 default=None, title="The description of the item", max_length=300
11 )
12 price: float = Field(gt=0, description="The price must be greater than zero") 1abcde
13 tax: float | None = None 1abcde
16@app.put("/items/{item_id}") 1abcde
17async def update_item(item_id: int, item: Item = Body(embed=True)): 1abcde
18 results = {"item_id": item_id, "item": item} 1fghijklmno
19 return results 1fghijklmno