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