mirror of https://github.com/tiangolo/fastapi.git
Merge e03b302d97 into cc6ced6345
This commit is contained in:
commit
a3deb9b96f
|
|
@ -246,6 +246,8 @@ def get_openapi_operation_metadata(
|
|||
if route.description:
|
||||
operation["description"] = route.description
|
||||
operation_id = route.operation_id or route.unique_id
|
||||
if len(route.methods) > 1:
|
||||
operation_id = f"{operation_id}_{method.lower()}"
|
||||
if operation_id in operation_ids:
|
||||
message = (
|
||||
f"Duplicate Operation ID {operation_id} for function "
|
||||
|
|
|
|||
|
|
@ -108,7 +108,10 @@ def generate_unique_id(route: "APIRoute") -> str:
|
|||
operation_id = f"{route.name}{route.path_format}"
|
||||
operation_id = re.sub(r"\W", "_", operation_id)
|
||||
assert route.methods
|
||||
operation_id = f"{operation_id}_{list(route.methods)[0].lower()}"
|
||||
|
||||
if len(route.methods) == 1:
|
||||
operation_id = f"{operation_id}_{list(route.methods)[0].lower()}"
|
||||
|
||||
return operation_id
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -199,6 +199,11 @@ def get_query_type_frozenset(query: frozenset[int] = Query(...)):
|
|||
return ",".join(map(str, sorted(query)))
|
||||
|
||||
|
||||
@app.api_route("/multiple-methods", methods=["GET", "POST"])
|
||||
def multiple_methods():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
|
||||
@app.get("/query/list")
|
||||
def get_query_list(device_ids: list[int] = Query()) -> list[int]:
|
||||
return device_ids
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ client = TestClient(app)
|
|||
[
|
||||
("/api_route", 200, {"message": "Hello World"}),
|
||||
("/non_decorated_route", 200, {"message": "Hello World"}),
|
||||
("/multiple-methods", 200, {"message": "Hello World"}),
|
||||
("/nonexistent", 404, {"detail": "Not Found"}),
|
||||
],
|
||||
)
|
||||
|
|
@ -1158,6 +1159,28 @@ def test_openapi_schema():
|
|||
},
|
||||
}
|
||||
},
|
||||
"/multiple-methods": {
|
||||
"get": {
|
||||
"summary": "Multiple Methods",
|
||||
"operationId": "multiple_methods_multiple_methods_get",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
},
|
||||
"post": {
|
||||
"summary": "Multiple Methods",
|
||||
"operationId": "multiple_methods_multiple_methods_post",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
"/query/list": {
|
||||
"get": {
|
||||
"summary": "Get Query List",
|
||||
|
|
@ -1246,6 +1269,17 @@ def test_openapi_schema():
|
|||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"HTTPValidationError": {
|
||||
"title": "HTTPValidationError",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"detail": {
|
||||
"title": "Detail",
|
||||
"type": "array",
|
||||
"items": {"$ref": "#/components/schemas/ValidationError"},
|
||||
}
|
||||
},
|
||||
},
|
||||
"ValidationError": {
|
||||
"title": "ValidationError",
|
||||
"required": ["loc", "msg", "type"],
|
||||
|
|
@ -1264,17 +1298,6 @@ def test_openapi_schema():
|
|||
"ctx": {"title": "Context", "type": "object"},
|
||||
},
|
||||
},
|
||||
"HTTPValidationError": {
|
||||
"title": "HTTPValidationError",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"detail": {
|
||||
"title": "Detail",
|
||||
"type": "array",
|
||||
"items": {"$ref": "#/components/schemas/ValidationError"},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue