Coverage for tests / test_repeated_parameter_alias.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI, Path, Query, status 1abcd
2from fastapi.testclient import TestClient 1abcd
3from inline_snapshot import snapshot 1abcd
5app = FastAPI() 1abcd
8@app.get("/{repeated_alias}") 1abcd
9def get_parameters_with_repeated_aliases( 1abcd
10 path: str = Path(..., alias="repeated_alias"),
11 query: str = Query(..., alias="repeated_alias"),
12):
13 return {"path": path, "query": query} 1efg
16client = TestClient(app) 1abcd
19def test_get_parameters(): 1abcd
20 response = client.get("/test_path", params={"repeated_alias": "test_query"}) 1efg
21 assert response.status_code == 200, response.text 1efg
22 assert response.json() == {"path": "test_path", "query": "test_query"} 1efg
25def test_openapi_schema(): 1abcd
26 response = client.get("/openapi.json") 1hij
27 assert response.status_code == status.HTTP_200_OK 1hij
28 assert response.json() == snapshot( 1hij
29 {
30 "components": {
31 "schemas": {
32 "HTTPValidationError": {
33 "properties": {
34 "detail": {
35 "items": {
36 "$ref": "#/components/schemas/ValidationError"
37 },
38 "title": "Detail",
39 "type": "array",
40 }
41 },
42 "title": "HTTPValidationError",
43 "type": "object",
44 },
45 "ValidationError": {
46 "properties": {
47 "ctx": {"title": "Context", "type": "object"},
48 "input": {"title": "Input"},
49 "loc": {
50 "items": {
51 "anyOf": [{"type": "string"}, {"type": "integer"}]
52 },
53 "title": "Location",
54 "type": "array",
55 },
56 "msg": {"title": "Message", "type": "string"},
57 "type": {"title": "Error Type", "type": "string"},
58 },
59 "required": ["loc", "msg", "type"],
60 "title": "ValidationError",
61 "type": "object",
62 },
63 }
64 },
65 "info": {"title": "FastAPI", "version": "0.1.0"},
66 "openapi": "3.1.0",
67 "paths": {
68 "/{repeated_alias}": {
69 "get": {
70 "operationId": "get_parameters_with_repeated_aliases__repeated_alias__get",
71 "parameters": [
72 {
73 "in": "path",
74 "name": "repeated_alias",
75 "required": True,
76 "schema": {"title": "Repeated Alias", "type": "string"},
77 },
78 {
79 "in": "query",
80 "name": "repeated_alias",
81 "required": True,
82 "schema": {"title": "Repeated Alias", "type": "string"},
83 },
84 ],
85 "responses": {
86 "200": {
87 "content": {"application/json": {"schema": {}}},
88 "description": "Successful Response",
89 },
90 "422": {
91 "content": {
92 "application/json": {
93 "schema": {
94 "$ref": "#/components/schemas/HTTPValidationError"
95 }
96 }
97 },
98 "description": "Validation Error",
99 },
100 },
101 "summary": "Get Parameters With Repeated Aliases",
102 }
103 }
104 },
105 }
106 )