Coverage for docs_src / generate_clients / tutorial003_py310.py: 100%
23 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI 1abcd
2from fastapi.routing import APIRoute 1abcd
3from pydantic import BaseModel 1abcd
6def custom_generate_unique_id(route: APIRoute): 1abcd
7 return f"{route.tags[0]}-{route.name}" 1abcd
10app = FastAPI(generate_unique_id_function=custom_generate_unique_id) 1abcd
13class Item(BaseModel): 1abcd
14 name: str 1abcd
15 price: float 1abcd
18class ResponseMessage(BaseModel): 1abcd
19 message: str 1abcd
22class User(BaseModel): 1abcd
23 username: str 1abcd
24 email: str 1abcd
27@app.post("/items/", response_model=ResponseMessage, tags=["items"]) 1abcd
28async def create_item(item: Item): 1abcd
29 return {"message": "Item received"} 1efg
32@app.get("/items/", response_model=list[Item], tags=["items"]) 1abcd
33async def get_items(): 1abcd
34 return [ 1hij
35 {"name": "Plumbus", "price": 3},
36 {"name": "Portal Gun", "price": 9001},
37 ]
40@app.post("/users/", response_model=ResponseMessage, tags=["users"]) 1abcd
41async def create_user(user: User): 1abcd
42 return {"message": "User received"} 1klm