Coverage for docs_src/response_model/tutorial004.py: 100%
14 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 typing import List, Union 1abcde
3from fastapi import FastAPI 1abcde
4from pydantic import BaseModel 1abcde
6app = FastAPI() 1abcde
9class Item(BaseModel): 1abcde
10 name: str 1abcde
11 description: Union[str, None] = None 1abcde
12 price: float 1abcde
13 tax: float = 10.5 1abcde
14 tags: List[str] = [] 1abcde
17items = { 1abcde
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) 1abcde
25async def read_item(item_id: str): 1abcde
26 return items[item_id] 1abcde