Invalid specs are accepted from swagger spec validator (operation responses cannot contain references)
macisamuele opened this issue · 0 comments
macisamuele commented
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