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
Fix body validator different error codes for bad Content-Types. #629
Fix body validator different error codes for bad Content-Types. #629
Conversation
nice, I noticed this too when working OpenAPI3 support. |
@dtkav That's not a big bug and not a big fix actually, it only changes 400 error to 415. |
my bad @positron96 , I think i am confusing it with a different issue where connexion accepts form data even if the mimetype is wrong. |
That sounds serious. Is there a description of the bug?
…On Jul 20, 2018 09:24, "Daniel Grossmann-Kavanagh" ***@***.***> wrote:
my bad @positron96 <https://github.com/positron96> , I think i am
confusing it with a different issue where connexion accepts form data even
if the mimetype is wrong.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#629 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB_4rlEM75YfLRbTMhSAtrKBQ1SNXdbnks5uIT96gaJpZM4VUmBk>
.
|
I dug into this a little bit to refresh my memory. I couldn't remember if it was a problem with my branch, or also on master. /test-formData-param:
post:
summary: Test formData parameter
operationId: fakeapi.hello.test_formdata_param
consumes:
- application/json # connexion assumes application/json if this is blank
# - application/x-www-form-urlencoded
parameters:
- name: formData
type: string
in: formData
required: true
responses:
200:
description: OK The client still sends the correct content type alongside the form data, but the spec doesn't specify that the endpoint consumes form content types, and connexion isn't strict - it let's the form data through. It's an oddity of the swagger 2.0 spec that you can specify You can reproduce this by running: cd tests
PYTHONPATH=$PWD connexion run fixtures/simple/swagger.yaml -p 9090
# in another terminal...
curl -X POST -F "formData=somedata" http://localhost:9090/v1.0/test-formData-param Either way, your change looks good to me! |
connexion/decorators/validation.py
Outdated
@@ -101,7 +101,8 @@ def wrapper(request): | |||
if all_json(self.consumes): | |||
data = request.json | |||
|
|||
if data is None and len(request.body) > 0 and not self.is_null_value_valid: | |||
empty_body = len(request.body) == 0 and len(request.form) == 0 and len(request.files) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not(request.body or request.form or request.files)
would be more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it definitely will
@positron96 I agree with @dtkav this should target the |
@jmcs It turns out I was conflating this change with some other behavior (elaborated on above). |
BTW, I've changed the code as requested. |
👍 |
Thanks for the PR. |
Fixes #628 .
Changes proposed in this pull request: