-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
Content negotiation and response validation assumes incorrect schema for validation #860
Comments
If anyone is interested, for the time being I am hacking the validation for my particular case by using a custom response validator:
with the appropriate initialization on my app:
|
Thanks for the pointer, I'll take a look to that branch this week. |
6 tasks
Fixed since #1591 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
In an API written in OAS v3 (which supports content negotiation), when an operation has two different response mimetypes and one of them is not json-compatible, the validation assumes
application/json
. This entails some errors on the validation.Expected behaviour
The validation should honor the API specification and use the schema of the associated content type. One should be able to have an operation that can respond
application/json
andapplication/octet-stream
according to theAccept
header.Actual behaviour
When the operation initializes its mimetype and finds that the operation can produce more than one type, it assumes that it is
application/json
. However, if the implementation's response is not json or does, the validation will fail.Steps to reproduce
application/json
andapplication/content-type
. For example:Run connexion with response validation enabled.
Request the operation from a client using the Accept header to request
application/octet-stream
. In the example above, it will fail with aUnicodeDecodeError: 'utf-8' codec can't decode byte
while trying tointerpret the binary contents as json.
Additional info:
After some analysis, I have identified some potential sources that produce this behavior.
First, it seems that
connexion.operations.abstract.AbstrsactOperation.get_mimetype
incorrectlyassumes that the mimetype is
application/json
when the operation does notproduce json for all its responses (according to
connexion.utils.all_json
.This makes the
ResponseValidator
have an incorrect mimetype field. Then,ResponseValidator.is_json_Schema_compatible
is confused by this and eventuallythe
ResponseValidator.validate_response
callsjson.loads
, which fails and itis interpreted as a validation error.
Output of the commands:
python --version
Python 3.7.1
pip show connexion | grep "^Version\:"
Version: 2.2.0
The text was updated successfully, but these errors were encountered: