Coverage for docs_src / additional_responses / tutorial001_py310.py: 100%
14 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.responses import JSONResponse 1abcd
3from pydantic import BaseModel 1abcd
6class Item(BaseModel): 1abcd
7 id: str 1abcd
8 value: str 1abcd
11class Message(BaseModel): 1abcd
12 message: str 1abcd
15app = FastAPI() 1abcd
18@app.get("/items/{item_id}", response_model=Item, responses={404: {"model": Message}}) 1abcd
19async def read_item(item_id: str): 1abcd
20 if item_id == "foo": 1efghij
21 return {"id": "foo", "value": "there goes my hero"} 1egi
22 return JSONResponse(status_code=404, content={"message": "Item not found"}) 1fhj