Coverage for docs_src/extra_models/tutorial003.py: 100%
16 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 1abcde
3from fastapi import FastAPI 1abcde
4from pydantic import BaseModel 1abcde
6app = FastAPI() 1abcde
9class BaseItem(BaseModel): 1abcde
10 description: str 1abcde
11 type: str 1abcde
14class CarItem(BaseItem): 1abcde
15 type: str = "car" 1abcde
18class PlaneItem(BaseItem): 1abcde
19 type: str = "plane" 1abcde
20 size: int 1abcde
23items = { 1abcde
24 "item1": {"description": "All my friends drive a low rider", "type": "car"},
25 "item2": {
26 "description": "Music is my aeroplane, it's my aeroplane",
27 "type": "plane",
28 "size": 5,
29 },
30}
33@app.get("/items/{item_id}", response_model=Union[PlaneItem, CarItem]) 1abcde
34async def read_item(item_id: str): 1abcde
35 return items[item_id] 1abcde