Coverage for docs_src / response_model / tutorial001_py310.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from typing import Any 1aghbcdef

2 

3from fastapi import FastAPI 1aghbcdef

4from pydantic import BaseModel 1aghbcdef

5 

6app = FastAPI() 1aghbcdef

7 

8 

9class Item(BaseModel): 1aghbcdef

10 name: str 1abcdef

11 description: str | None = None 1aghbcdef

12 price: float 1abcdef

13 tax: float | None = None 1aghbcdef

14 tags: list[str] = [] 1aghbcdef

15 

16 

17@app.post("/items/", response_model=Item) 1aghbcdef

18async def create_item(item: Item) -> Any: 1aghbcdef

19 return item 1ijklmno

20 

21 

22@app.get("/items/", response_model=list[Item]) 1aghbcdef

23async def read_items() -> Any: 1aghbcdef

24 return [ 1pqrs

25 {"name": "Portal Gun", "price": 42.0}, 

26 {"name": "Plumbus", "price": 32.0}, 

27 ]