Yelp/swagger_spec_validator

[2.0.4] Validation failure with path parameter

Closed this issue · 1 comments

Abstract

When I swagger_spec_validator 2.0.4 (actually in my case, it's called from bravado-core) with path parameter, it fails all time.

Reproduce sample

spec.json

{
  "swagger": "2.0",
  "info": {
    "title": "Sample",
    "version": "1.0.0"
  },
  "schemes": [
    "http"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/api/v1/communications/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "type": "string"
        }
      ],
      "get": {
        "tags": [
          "Communications"
        ],
        "operationId": "CommunicationsDetail_read",
        "responses": {
          "200": {
            "description": "success",
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}

python code

import json
from swagger_spec_validator import validator20

spec = json.load(open('spec.json'))
validator20.validate_spec(spec)

SwaggerValidationError:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    validator20.validate_spec(spec)
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/swagger_spec_validator/validator20.py", line 82, in validate_spec
    http_handlers=http_handlers)
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/swagger_spec_validator/common.py", line 22, in wrapper
    sys.exc_info()[2])
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/swagger_spec_validator/common.py", line 17, in wrapper
    return method(*args, **kwargs)
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/swagger_spec_validator/validator20.py", line 125, in validate_json
    cls=Draft4Validator)
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/swagger_spec_validator/ref_validators.py", line 34, in validate
    instance_cls(schema, *args, **kwargs).validate(instance)
  File "/Users/takuro/git/swagger-validator-sandbox/venv/lib/python3.6/site-packages/jsonschema/validators.py", line 130, in validate
    raise error
swagger_spec_validator.common.SwaggerValidationError: {'name': 'id', 'in': 'path', 'type': 'string'} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['parameters']['items']:
    {'oneOf': [{'$ref': '#/definitions/parameter'},
               {'$ref': '#/definitions/jsonReference'}]}

On instance['paths']['/api/v1/communications/{id}']['parameters'][0]:
    {'in': 'path', 'name': 'id', 'type': 'string'}

This error occurs with 2.0.4. 2.0.2 does not raise any validation error with this spec.

Conclusion

I think it may be a bug related to 2.0.4. It would be great if you could patch this bug. Or if I can find time, I will send PR.

Sorry my mistake..

I added "required": ture to the path parameter's definition, it passed. And "required" is the required parameter according to swagger spec document.