Coverage for docs_src/dataclasses/tutorial002.py: 100%

14 statements  

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

1from dataclasses import dataclass, field 1abcde

2from typing import List, Union 1abcde

3 

4from fastapi import FastAPI 1abcde

5 

6 

7@dataclass 1abcde

8class Item: 1abcde

9 name: str 1abcde

10 price: float 1abcde

11 tags: List[str] = field(default_factory=list) 1abcde

12 description: Union[str, None] = None 1abcde

13 tax: Union[float, None] = None 1abcde

14 

15 

16app = FastAPI() 1abcde

17 

18 

19@app.get("/items/next", response_model=Item) 1abcde

20async def read_next_item(): 1abcde

21 return { 1abcde

22 "name": "Island In The Moon", 

23 "price": 12.99, 

24 "description": "A place to be playin' and havin' fun", 

25 "tags": ["breater"], 

26 }