1
from fastapi import Depends, FastAPI, Header, status
2
from fastapi.testclient import TestClient
7
def get_header(*, someheader: str = Header()):
11
def get_something_else(*, someheader: str = Depends(get_header)):
12
return f"{someheader}123"
16
def get_deps(dep1: str = Depends(get_header), dep2: str = Depends(get_something_else)):
17
return {"dep1": dep1, "dep2": dep2}
20
client = TestClient(app)
25
"HTTPValidationError": {
28
"items": {"$ref": "#/components/schemas/ValidationError"},
33
"title": "HTTPValidationError",
39
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
43
"msg": {"title": "Message", "type": "string"},
44
"type": {"title": "Error " "Type", "type": "string"},
46
"required": ["loc", "msg", "type"],
47
"title": "ValidationError",
52
"info": {"title": "FastAPI", "version": "0.1.0"},
57
"operationId": "get_deps__get",
63
"schema": {"title": "Someheader", "type": "string"},
68
"content": {"application/json": {"schema": {}}},
69
"description": "Successful " "Response",
75
"$ref": "#/components/schemas/HTTPValidationError"
79
"description": "Validation " "Error",
82
"summary": "Get Deps",
90
response = client.get("/openapi.json")
91
assert response.status_code == status.HTTP_200_OK
92
actual_schema = response.json()
93
assert actual_schema == schema
95
len(actual_schema["paths"]["/"]["get"]["parameters"]) == 1
100
response = client.get("/", headers={"someheader": "hello"})
101
assert response.status_code == status.HTTP_200_OK
102
assert response.json() == {"dep1": "hello", "dep2": "hello123"}