Coverage for docs_src/response_model/tutorial004.py: 100%
14 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 typing import List, Union 1abcdef
3from fastapi import FastAPI 1abcdef
4from pydantic import BaseModel 1abcdef
6app = FastAPI() 1abcdef
9class Item(BaseModel): 1abcdef
10 name: str 1abcdef
11 description: Union[str, None] = None 1abcdef
12 price: float 1abcdef
13 tax: float = 10.5 1abcdef
14 tags: List[str] = [] 1abcdef
17items = { 1abcdef
18 "foo": {"name": "Foo", "price": 50.2},
19 "bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
20 "baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []},
21}
24@app.get("/items/{item_id}", response_model=Item, response_model_exclude_unset=True) 1abcdef
25async def read_item(item_id: str): 1abcdef
26 return items[item_id] 1ghijkl