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

Impossible to return mime type other than application/json if multiple mime types are defined #1500

Closed
aigielsk opened this issue Mar 24, 2022 · 2 comments

Comments

@aigielsk
Copy link

We have an API spec in which we have a download operation that is supposed to return application/octet-stream (with status code 200). In case something is wrong with the user input another status codes are defined (400 and 404) that are supposed to return application/json.

This seems impossible to achieve with connexion. It always assumes application/json mime type and attempts to parse the JSON before sending the response.

Some details:
The method get_mimetype:

def get_mimetype(self):
first checks if all returned mime types are the same and then (if this is not the case) - it only allows a non-JSON mime type if there is just one type defined:

elif len(self.produces) == 1:
return self.produces[0]

Otherwise it returns the DEFAULT_MIMETYPE, which is application/json.

It should be possible to define the returned mime type per returned status code.

@RobbeSneyders
Copy link
Member

HI @aigielsk, handling multiple mimetypes on the same endpoint is indeed a current limitation of connexion (see #653). You can work around this by returning a response object with the correct mimetype set.

@RobbeSneyders
Copy link
Member

Fixed in #1588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants