Coverage for docs_src / extra_models / tutorial003_py310.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-21 17:29 +0000

1from fastapi import FastAPI 1abc

2from pydantic import BaseModel 1abc

3 

4app = FastAPI() 1abc

5 

6 

7class BaseItem(BaseModel): 1abc

8 description: str 1abc

9 type: str 1abc

10 

11 

12class CarItem(BaseItem): 1abc

13 type: str = "car" 1abc

14 

15 

16class PlaneItem(BaseItem): 1abc

17 type: str = "plane" 1abc

18 size: int 1abc

19 

20 

21items = { 1abc

22 "item1": {"description": "All my friends drive a low rider", "type": "car"}, 

23 "item2": { 

24 "description": "Music is my aeroplane, it's my aeroplane", 

25 "type": "plane", 

26 "size": 5, 

27 }, 

28} 

29 

30 

31@app.get("/items/{item_id}", response_model=PlaneItem | CarItem) 1abc

32async def read_item(item_id: str): 1abc

33 return items[item_id] 1defghi