Coverage for docs_src/body_fields/tutorial001_py310.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1from fastapi import Body, FastAPI 1abcd

2from pydantic import BaseModel, Field 1abcd

3 

4app = FastAPI() 1abcd

5 

6 

7class Item(BaseModel): 1abcd

8 name: str 1abcd

9 description: str | None = Field( 1abcd

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") 1abcd

13 tax: float | None = None 1abcd

14 

15 

16@app.put("/items/{item_id}") 1abcd

17async def update_item(item_id: int, item: Item = Body(embed=True)): 1abcd

18 results = {"item_id": item_id, "item": item} 1efghijkl

19 return results 1efghijkl