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

[bravado] jsonschema.validate is failing on request validation #126

Closed
prat0318 opened this issue Mar 22, 2015 · 2 comments
Closed

[bravado] jsonschema.validate is failing on request validation #126

prat0318 opened this issue Mar 22, 2015 · 2 comments
Assignees

Comments

@prat0318
Copy link
Contributor

I tried this:

swagger_client = client.get_client('http://petstore.swagger.io/v2/swagger.json')
swagger_client.pet.findPetsByStatus(status=['available']).result()

Which throws back:

---> 33     jsonschema.validate(value, spec)
     34
     35

/usr/lib/pymodules/python2.6/jsonschema/validators.pyc in validate(instance, schema, cls, *args, **kwargs)
    504     """
    505     if cls is None:
    506         cls = validator_for(schema)
--> 507     cls.check_schema(schema)
    508     cls(schema, *args, **kwargs).validate(instance)

/usr/lib/pymodules/python2.6/jsonschema/validators.pyc in check_schema(cls, schema)
     74         def check_schema(cls, schema):
     75             for error in cls(cls.META_SCHEMA).iter_errors(schema):
---> 76                 raise SchemaError.create_from(error)
     77
     78         def iter_errors(self, instance, _schema=None):

SchemaError: False is not of type u'array'

Failed validating u'type' in schema[u'properties'][u'required']:
    {u'items': {u'type': u'string'},
     u'minItems': 1,
     u'type': u'array',
     u'uniqueItems': True}

On instance[u'required']:
    False

It looks like swagger_spec can not be directly treated as json_schema to validate the request.

On removing required field from the spec, and retrying gives:

ValidationError: ['available'] is not one of [u'available', u'pending', u'sold']

Failed validating u'enum' in schema:
    {u'collectionFormat': u'multi',
     u'default': u'available',
     u'description': u'Status values that need to be considered for filter',
     u'enum': [u'available', u'pending', u'sold'],
     u'in': u'query',
     u'items': {u'type': u'string'},
     u'name': u'status',
     u'type': u'array'}

On instance:
    ['available']

In other words, jsonschema.validate will not work in these cases.

@prat0318 prat0318 added the bug label Mar 22, 2015
@dnephin
Copy link
Contributor

dnephin commented Mar 23, 2015

We should create our own validators using jsonschema. It actually provides an excellent mechanism for doing this, and the author is very strict about keeping backwards compatibility.

You can see an example of this here: https://github.com/striglia/pyramid_swagger/pull/90/files#diff-154107719748d5873abea20526a5c82dR109 using jsonschema.validators.extend().

So instead of using the Draft4Validator, we would use our own Swagger20RequestValidator

@prat0318
Copy link
Contributor Author

Closed via #136

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants