-
-
Notifications
You must be signed in to change notification settings - Fork 773
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
Decode error with validate_responses=True and multiple response types specified #1434
Comments
I just stumbled across the same issue. What happens here is that def get_mimetype(self):
"""
If the endpoint has no 'produces' then the default is
'application/json'.
:rtype str
"""
if all_json(self.produces):
try:
return self.produces[0]
except IndexError:
return DEFAULT_MIMETYPE
elif len(self.produces) == 1:
return self.produces[0]
else:
return DEFAULT_MIMETYPE A method with more than one produced response type including a non-JSON type will always receive DEFAULT_MIMETYPE, which is JSON again. Therefore, the As far as I understand the structure, a |
Here's a hacky workaround that trusts the returned content type by an operation to disable validation for non-JSON responses: class ResponseValidatorWithBinarySupport(ResponseValidator):
def validate_response(self, data, status_code, headers, url):
# Skip validation for non JSON-like reponses such as images and files
if not all_json([headers.get("Content-Type", "application/json")]):
return
super().validate_response(data, status_code, headers, url)
# ...
app.add_api(
# ...
validator_map={"response": ResponseValidatorWithBinarySupport},
) |
Thanks @languitar I'll give that a shot. |
Can confirm the above workaround was successful. Thanks again. |
Looks like this was already tracked at #860 |
Thanks for the report. |
Description
Sample repo demonstrating the issue.
With the following in my swagger definition:
And having
validate_responses=True
I'm receiving the following error:It appears having the 401 response type set to
application/json
is causing the response validator to try to parse my PDF as JSON. I'm curious if the way I'm returning the PDF may be causing this issue or if this is genuinely a problem so wanted to post an issue to get some feedback.Expected behaviour
Calling the endpoint should not produce an error.
Actual behaviour
Calling the endpoint is causing the above error.
Steps to reproduce
Run the linked sample repo with
FLASK_APP=test flask run
then
curl http://localhost:5000/document
Additional info:
Output of the commands:
python --version
Python 3.8.5
pip show connexion | grep "^Version\:"
Version: 2.9.0
The text was updated successfully, but these errors were encountered: