Coverage for docs_src/response_model/tutorial005_py310.py: 100%
15 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
14items = { 1abcd
15 "foo": {"name": "Foo", "price": 50.2},
16 "bar": {"name": "Bar", "description": "The Bar fighters", "price": 62, "tax": 20.2},
17 "baz": {
18 "name": "Baz",
19 "description": "There goes my baz",
20 "price": 50.2,
21 "tax": 10.5,
22 },
23}
26@app.get( 1abcd
27 "/items/{item_id}/name",
28 response_model=Item,
29 response_model_include={"name", "description"},
30)
31async def read_item_name(item_id: str): 1abcd
32 return items[item_id] 1efgh
35@app.get("/items/{item_id}/public", response_model=Item, response_model_exclude={"tax"}) 1abcd
36async def read_item_public_data(item_id: str): 1abcd
37 return items[item_id] 1ijkl