Coverage for docs_src / body_fields / tutorial001_py310.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from fastapi import Body, FastAPI 1aefbcd
2from pydantic import BaseModel, Field 1aefbcd
4app = FastAPI() 1aefbcd
7class Item(BaseModel): 1aefbcd
8 name: str 1abcd
9 description: str | None = Field( 1aefbcd
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") 1aefbcd
13 tax: float | None = None 1aefbcd
16@app.put("/items/{item_id}") 1aefbcd
17async def update_item(item_id: int, item: Item = Body(embed=True)): 1aefbcd
18 results = {"item_id": item_id, "item": item} 1ghijklm
19 return results 1ghijklm