Response type hint should work with Annotated[Response, Depends(...)].
()
| 12 | |
| 13 | |
| 14 | def test_response_with_depends_annotated(): |
| 15 | """Response type hint should work with Annotated[Response, Depends(...)].""" |
| 16 | app = FastAPI() |
| 17 | |
| 18 | def modify_response(response: Response) -> Response: |
| 19 | response.headers["X-Custom"] = "modified" |
| 20 | return response |
| 21 | |
| 22 | @app.get("/") |
| 23 | def endpoint(response: Annotated[Response, Depends(modify_response)]): |
| 24 | return {"status": "ok"} |
| 25 | |
| 26 | client = TestClient(app) |
| 27 | resp = client.get("/") |
| 28 | |
| 29 | assert resp.status_code == 200 |
| 30 | assert resp.json() == {"status": "ok"} |
| 31 | assert resp.headers.get("X-Custom") == "modified" |
| 32 | |
| 33 | |
| 34 | def test_response_with_depends_default(): |