1
from fastapi import FastAPI, Path, Query, status
2
from fastapi.testclient import TestClient
7
@app.get("/{repeated_alias}")
8
def get_parameters_with_repeated_aliases(
9
path: str = Path(..., alias="repeated_alias"),
10
query: str = Query(..., alias="repeated_alias"),
12
return {"path": path, "query": query}
15
client = TestClient(app)
18
def test_get_parameters():
19
response = client.get("/test_path", params={"repeated_alias": "test_query"})
20
assert response.status_code == 200, response.text
21
assert response.json() == {"path": "test_path", "query": "test_query"}
24
def test_openapi_schema():
25
response = client.get("/openapi.json")
26
assert response.status_code == status.HTTP_200_OK
27
actual_schema = response.json()
28
assert actual_schema == {
31
"HTTPValidationError": {
34
"items": {"$ref": "#/components/schemas/ValidationError"},
39
"title": "HTTPValidationError",
46
"anyOf": [{"type": "string"}, {"type": "integer"}]
51
"msg": {"title": "Message", "type": "string"},
52
"type": {"title": "Error Type", "type": "string"},
54
"required": ["loc", "msg", "type"],
55
"title": "ValidationError",
60
"info": {"title": "FastAPI", "version": "0.1.0"},
63
"/{repeated_alias}": {
65
"operationId": "get_parameters_with_repeated_aliases__repeated_alias__get",
69
"name": "repeated_alias",
71
"schema": {"title": "Repeated Alias", "type": "string"},
75
"name": "repeated_alias",
77
"schema": {"title": "Repeated Alias", "type": "string"},
82
"content": {"application/json": {"schema": {}}},
83
"description": "Successful Response",
89
"$ref": "#/components/schemas/HTTPValidationError"
93
"description": "Validation Error",
96
"summary": "Get Parameters With Repeated Aliases",