Coverage for docs_src / body / tutorial002_py310.py: 100%
15 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 FastAPI 1abfgcde
2from pydantic import BaseModel 1abfgcde
5class Item(BaseModel): 1abfgcde
6 name: str 1abcde
7 description: str | None = None 1abfgcde
8 price: float 1abcde
9 tax: float | None = None 1abfgcde
12app = FastAPI() 1abfgcde
15@app.post("/items/") 1abfgcde
16async def create_item(item: Item): 1abfgcde
17 item_dict = item.model_dump() 1hipqjklmrsnotu
18 if item.tax is not None: 1hipqjklmrsnotu
19 price_with_tax = item.price + item.tax 1hijklmno
20 item_dict.update({"price_with_tax": price_with_tax}) 1hijklmno
21 return item_dict 1hipqjklmrsnotu