-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: handle non-dict DefinitionBody path item in _openapi_postprocess #2216
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: handle non-dict DefinitionBody path item in _openapi_postprocess #2216
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2216 +/- ##
===========================================
+ Coverage 93.58% 94.45% +0.86%
===========================================
Files 90 95 +5
Lines 6124 6560 +436
Branches 1260 1324 +64
===========================================
+ Hits 5731 6196 +465
+ Misses 183 169 -14
+ Partials 210 195 -15
Continue to review full report at Codecov.
|
… into handle_null_fields_in_definitionbody_options
@staticmethod | ||
def validate_is_dict(obj, exception_message): | ||
""" | ||
Throws exception if obj is not a dict | ||
:param obj: object being validated | ||
:param exception_message: message to include in exception if obj is not a dict | ||
""" | ||
|
||
if not isinstance(obj, dict): | ||
raise InvalidDocumentException([InvalidTemplateException(exception_message)]) | ||
|
||
@staticmethod | ||
def validate_path_item_is_dict(path_item, path): | ||
""" | ||
Throws exception if path_item is not a dict | ||
:param path_item: path_item (value at the path) being validated | ||
:param path: path name | ||
""" | ||
|
||
SwaggerEditor.validate_is_dict( | ||
path_item, "Value of '{}' path must be a dictionary according to Swagger spec.".format(path) | ||
) | ||
|
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.
not sure where's the best place to add this, but thought this was good for now since some validation is done in this file. Also am I supposed to also add this to open_api.py
?
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.
why did you add a new method, and did not used validate_is_dict
. The new method is just a wrapper for the existing one.
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.
because this same action (validating the path item) would be done in swagger.py and api_generator.py. I mainly just didn't want to repeat the error message and make sure that it was consistent in every place if it's changed in the future. Not sure if there's a better way of doing it, where I just generate the error message.
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.
ok
Issue #, if available:
Description of changes:
_openapi_postprocess
expects the value at a path to be a dict. The following template would cause an unhandled error:This PR checks that it is a dict and throws an error if it's not. Also did some refactoring while I updated this part of the code.
Description of how you validated changes:
Added end-to-end tests
Checklist:
make pr
passesExamples?
Please reach out in the comments, if you want to add an example. Examples will be
added to
sam init
through https://github.com/awslabs/aws-sam-cli-app-templates/By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.