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

12 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi import FastAPI 1abc

2from fastapi.responses import FileResponse 1abc

3from pydantic import BaseModel 1abc

4 

5 

6class Item(BaseModel): 1abc

7 id: str 1abc

8 value: str 1abc

9 

10 

11app = FastAPI() 1abc

12 

13 

14@app.get( 1abc

15 "/items/{item_id}", 

16 response_model=Item, 

17 responses={ 

18 200: { 

19 "content": {"image/png": {}}, 

20 "description": "Return the JSON item or an image.", 

21 } 

22 }, 

23) 

24async def read_item(item_id: str, img: bool | None = None): 1abc

25 if img: 1defghi

26 return FileResponse("image.png", media_type="image/png") 1egi

27 else: 

28 return {"id": "foo", "value": "there goes my hero"} 1dfh