1
from fastapi import Depends, FastAPI
2
from fastapi.testclient import TestClient
7
async def user_exists(user_id: int):
11
@app.get("/users/{user_id}", dependencies=[Depends(user_exists)])
12
async def read_users(user_id: int):
16
client = TestClient(app)
20
response = client.get("/users/42")
21
assert response.status_code == 200, response.text
24
def test_openapi_schema():
25
response = client.get("/openapi.json")
26
data = response.json()
29
"info": {"title": "FastAPI", "version": "0.1.0"},
33
"summary": "Read Users",
34
"operationId": "read_users_users__user_id__get",
38
"schema": {"title": "User Id", "type": "integer"},
45
"description": "Successful Response",
46
"content": {"application/json": {"schema": {}}},
49
"description": "Validation Error",
53
"$ref": "#/components/schemas/HTTPValidationError"
64
"HTTPValidationError": {
65
"title": "HTTPValidationError",
71
"items": {"$ref": "#/components/schemas/ValidationError"},
76
"title": "ValidationError",
77
"required": ["loc", "msg", "type"],
84
"anyOf": [{"type": "string"}, {"type": "integer"}]
87
"msg": {"title": "Message", "type": "string"},
88
"type": {"title": "Error Type", "type": "string"},