Browse Source

feat(openapi.utils): checks whether to superimpose an additional response's media_type over the default route's response class's media_type

pull/11232/head
Vinícius Aguiar 1 year ago
parent
commit
932659f49b
  1. 15
      fastapi/openapi/utils.py

15
fastapi/openapi/utils.py

@ -345,11 +345,15 @@ def get_openapi_path(
)
else:
response_schema = {}
operation.setdefault("responses", {}).setdefault(
status_code, {}
).setdefault("content", {}).setdefault(route_response_media_type, {})[
"schema"
] = response_schema
route_responses = dict((str(k), v) for k, v in route.responses.items())
if status_code not in route_responses or not route_responses.get(status_code).get('superimpose'):
operation.setdefault("responses", {}).setdefault(
status_code, {}
).setdefault("content", {}).setdefault(route_response_media_type, {})[
"schema"
] = response_schema
if route.responses:
operation_responses = operation.setdefault("responses", {})
for (
@ -358,6 +362,7 @@ def get_openapi_path(
) in route.responses.items():
process_response = additional_response.copy()
process_response.pop("model", None)
process_response.pop("superimpose", None)
status_code_key = str(additional_status_code).upper()
if status_code_key == "DEFAULT":
status_code_key = "default"

Loading…
Cancel
Save