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

Loading…
Cancel
Save