Coverage for docs_src/generate_clients/tutorial003.py: 100%
24 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1from typing import List 1abcdef
3from fastapi import FastAPI 1abcdef
4from fastapi.routing import APIRoute 1abcdef
5from pydantic import BaseModel 1abcdef
8def custom_generate_unique_id(route: APIRoute): 1abcdef
9 return f"{route.tags[0]}-{route.name}" 1abcdef
12app = FastAPI(generate_unique_id_function=custom_generate_unique_id) 1abcdef
15class Item(BaseModel): 1abcdef
16 name: str 1abcdef
17 price: float 1abcdef
20class ResponseMessage(BaseModel): 1abcdef
21 message: str 1abcdef
24class User(BaseModel): 1abcdef
25 username: str 1abcdef
26 email: str 1abcdef
29@app.post("/items/", response_model=ResponseMessage, tags=["items"]) 1abcdef
30async def create_item(item: Item): 1abcdef
31 return {"message": "Item received"} 1ghijkl
34@app.get("/items/", response_model=List[Item], tags=["items"]) 1abcdef
35async def get_items(): 1abcdef
36 return [ 1mnopqr
37 {"name": "Plumbus", "price": 3},
38 {"name": "Portal Gun", "price": 9001},
39 ]
42@app.post("/users/", response_model=ResponseMessage, tags=["users"]) 1abcdef
43async def create_user(user: User): 1abcdef
44 return {"message": "User received"} 1stuvwx