mirror of https://github.com/tiangolo/fastapi.git
This commit is contained in:
parent
ac93277d3b
commit
4359b9355f
|
|
@ -196,6 +196,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 "
|
||||
|
|
|
|||
|
|
@ -183,7 +183,8 @@ def generate_unique_id(route: "APIRoute") -> str:
|
|||
operation_id = route.name + route.path_format
|
||||
operation_id = re.sub(r"\W", "_", operation_id)
|
||||
assert route.methods
|
||||
operation_id = operation_id + "_" + list(route.methods)[0].lower()
|
||||
if len(route.methods) == 1:
|
||||
operation_id = operation_id + "_" + list(route.methods)[0].lower()
|
||||
return operation_id
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -192,3 +192,8 @@ def get_enum_status_code():
|
|||
@app.get("/query/frozenset")
|
||||
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"}
|
||||
|
|
|
|||
|
|
@ -1163,9 +1163,46 @@ 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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"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"],
|
||||
|
|
@ -1182,17 +1219,6 @@ def test_openapi_schema():
|
|||
"type": {"title": "Error Type", "type": "string"},
|
||||
},
|
||||
},
|
||||
"HTTPValidationError": {
|
||||
"title": "HTTPValidationError",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"detail": {
|
||||
"title": "Detail",
|
||||
"type": "array",
|
||||
"items": {"$ref": "#/components/schemas/ValidationError"},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue