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