Skip to content
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

Invalid specs are accepted from swagger spec validator (operation responses cannot contain references) #91

Closed
macisamuele opened this issue May 15, 2018 · 0 comments
Assignees

Comments

@macisamuele
Copy link
Collaborator

While working on Yelp/bravado-core#263, @sjaensch noticed that the produces swagger specs were not valid :(
This was caused by the fact that we started from invalid swagger specs and that swagger_spec_validator didn't spot the validation issue.

According to swagger 2.0 specs responses object should not contain references.
Allowed attributes are "default", http status codes, x-vendor attributes.

How to reproduce the described issue

In [1]: import sys

In [2]: sys.platform
Out[2]: 'darwin'

In [3]: sys.version_info
Out[3]: sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0)

In [4]: from swagger_spec_validator.validator20 import validate_json

In [5]: spec_dict = {
   ...:   "swagger": "2.0",
   ...:   "info": {
   ...:     "title": "Test",
   ...:     "version": "1.0"
   ...:   },
   ...:   "responses": {
   ...:     "default": {
   ...:         "description": "any response"
   ...:     }
   ...:   },
   ...:   "paths": {
   ...:     "/endpoint": {
   ...:         "get": {
   ...:             "responses": {
   ...:                 "$ref": "#/responses"
   ...:             }
   ...:         }
   ...:     }
   ...:   }
   ...: }

In [6]: validate_json(spec_dict, 'schemas/v2.0/schema.json')
Out[6]: <jsonschema.validators.RefResolver at 0x10bcde128>

In [7]:
Do you really want to exit ([y]/n)? y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant