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

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from typing import Union 1abc

2 

3from fastapi import FastAPI 1abc

4from pydantic import BaseModel 1abc

5 

6app = FastAPI() 1abc

7 

8 

9class BaseItem(BaseModel): 1abc

10 description: str 1abc

11 type: str 1abc

12 

13 

14class CarItem(BaseItem): 1abc

15 type: str = "car" 1abc

16 

17 

18class PlaneItem(BaseItem): 1abc

19 type: str = "plane" 1abc

20 size: int 1abc

21 

22 

23items = { 1abc

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} 

31 

32 

33@app.get("/items/{item_id}", response_model=Union[PlaneItem, CarItem]) 1abc

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

35 return items[item_id] 1abc