Coverage for docs_src/response_model/tutorial004_py310.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1from fastapi import FastAPI 1abcd
2from pydantic import BaseModel 1abcd
4app = FastAPI() 1abcd
7class Item(BaseModel): 1abcd
8 name: str 1abcd
9 description: str | None = None 1abcd
10 price: float 1abcd
11 tax: float = 10.5 1abcd
12 tags: list[str] = [] 1abcd
15items = { 1abcd
16 "foo": {"name": "Foo", "price": 50.2},
17 "bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
18 "baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []},
19}
22@app.get("/items/{item_id}", response_model=Item, response_model_exclude_unset=True) 1abcd
23async def read_item(item_id: str): 1abcd
24 return items[item_id] 1efgh