Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now will distinguish between status codes the expected inferred type #1957

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions connexion/decorators/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __call__(self, function: t.Callable) -> t.Callable:

def build_framework_response(self, handler_response):
data, status_code, headers = self._unpack_handler_response(handler_response)
content_type = self._infer_content_type(data, headers)
content_type = self._infer_content_type(data, status_code, headers)
if not self.framework.is_framework_response(data):
data = self._serialize_data(data, content_type=content_type)
status_code = status_code or self._infer_status_code(data)
Expand All @@ -37,7 +37,7 @@ def build_framework_response(self, handler_response):
)

@staticmethod
def _infer_content_type(data: t.Any, headers: dict) -> t.Optional[str]:
def _infer_content_type(data: t.Any, status_code: int, headers: dict) -> t.Optional[str]:
"""Infer the response content type from the returned data, headers and operation spec.

:param data: Response data
Expand All @@ -50,7 +50,7 @@ def _infer_content_type(data: t.Any, headers: dict) -> t.Optional[str]:
content_type = utils.extract_content_type(headers)

# TODO: don't default
produces = list(set(operation.produces))
produces = list(set(operation.responses.get(str(status_code), {}).get("content", {}).keys()))
if data is not None and not produces:
produces = ["application/json"]

Expand Down
Loading