Coverage for docs_src/additional_responses/tutorial002.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1from typing import Union 1abcdefg
3from fastapi import FastAPI 1abcdefg
4from fastapi.responses import FileResponse 1abcdefg
5from pydantic import BaseModel 1abcdefg
8class Item(BaseModel): 1abcdefg
9 id: str 1abcdefg
10 value: str 1abcdefg
13app = FastAPI() 1abcdefg
16@app.get( 1abcdefg
17 "/items/{item_id}",
18 response_model=Item,
19 responses={
20 200: {
21 "content": {"image/png": {}},
22 "description": "Return the JSON item or an image.",
23 }
24 },
25)
26async def read_item(item_id: str, img: Union[bool, None] = None): 1abcdefg
27 if img: 1hijklmnopqrstu
28 return FileResponse("image.png", media_type="image/png") 1ikmoqsu
29 else:
30 return {"id": "foo", "value": "there goes my hero"} 1hjlnprt