Coverage for docs_src / generate_clients / tutorial002_py310.py: 100%

20 statements  

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

1from fastapi import FastAPI 1adbc

2from pydantic import BaseModel 1adbc

3 

4app = FastAPI() 1adbc

5 

6 

7class Item(BaseModel): 1adbc

8 name: str 1abc

9 price: float 1abc

10 

11 

12class ResponseMessage(BaseModel): 1adbc

13 message: str 1abc

14 

15 

16class User(BaseModel): 1adbc

17 username: str 1abc

18 email: str 1abc

19 

20 

21@app.post("/items/", response_model=ResponseMessage, tags=["items"]) 1adbc

22async def create_item(item: Item): 1adbc

23 return {"message": "Item received"} 1efgh

24 

25 

26@app.get("/items/", response_model=list[Item], tags=["items"]) 1adbc

27async def get_items(): 1adbc

28 return [ 1ijkl

29 {"name": "Plumbus", "price": 3}, 

30 {"name": "Portal Gun", "price": 9001}, 

31 ] 

32 

33 

34@app.post("/users/", response_model=ResponseMessage, tags=["users"]) 1adbc

35async def create_user(user: User): 1adbc

36 return {"message": "User received"} 1mnop