-
-
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
Respect what the APIs consume #289
Conversation
@@ -125,6 +125,10 @@ def __init__(self, swagger_yaml_path, base_url=None, arguments=None, | |||
# API calls. | |||
self.produces = self.specification.get('produces', list()) # type: List[str] | |||
|
|||
# A list of MIME types the APIs can consume. This is global to all APIs but can be overridden on specific | |||
# API calls. |
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.
Please lets not duplicate comments.
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.
Sorry, what exactly do you mean? The comment relates to the consumes
param yet it's almost similar to the produces
. Should I rewrite it somehow or just remove?
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.
Its ok.
@31z4 Thanks for you PR. Could you please write at least one test covering this issue? |
@rafaelcaricio of course. Will do this a bit later as well as fix the emerged failures. |
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.
We also need a test when app_produces=[],
"produces" definition is optional in the OpenAPI spec.
@@ -114,6 +116,9 @@ def __call__(self, function): | |||
|
|||
@functools.wraps(function) | |||
def wrapper(*args, **kwargs): | |||
if 'application/json' not in self.consumes: | |||
return function(*args, **kwargs) |
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.
Is this necessary? We should have a test that covers this scenario.
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 is. Without it validation fails on the plain text request. Added a test.
request_body = flask.request.json | ||
except exceptions.BadRequest: | ||
request_body = None | ||
if 'application/json' in consumes: |
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.
This is not the right check. There are lots of "+json" mimetypes that have to be parsed as json
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.
You should use is_json_mimetype
for this check.
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.
Done.
@@ -114,6 +116,9 @@ def __call__(self, function): | |||
|
|||
@functools.wraps(function) | |||
def wrapper(*args, **kwargs): | |||
if 'application/json' not in self.consumes: |
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.
Again the wrong check. And I would put the validation logic inside the if to avoid repeating function(*args, **kwargs)
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.
Done.
@jmcs Thanks for your feedback! |
👍 |
Fixes #287.
Changes proposed in this pull request:
application/json
is not listed in theconsumes
then don't parse and validate the request body.