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

'type' is forced by bravado-core to be present in definitions #46

Closed
prat0318 opened this issue Aug 28, 2015 · 4 comments
Closed

'type' is forced by bravado-core to be present in definitions #46

prat0318 opened this issue Aug 28, 2015 · 4 comments

Comments

@prat0318
Copy link
Contributor

If definitions object does not contain a type field, validate method throws up like so:

5   2015-08-28 00:47:14,022 y_app.yelp.web.pyramid_app ERROR   : 'type'
Traceback (most recent call last):
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/pyramid_swagger/tween.py", line 181, in validator_tween
    swagger_handler.handle_response(response, op_or_validators_map)
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/pyramid_swagger/tween.py", line 412, in _validate
    return f(*args, **kwargs)
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/pyramid_swagger/tween.py", line 535, in swaggerize_response
    response_spec, op, PyramidSwaggerResponse(response))
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/bravado_core/response.py", line 156, in validate_response
    validate_response_body(op, response_spec, response)
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/bravado_core/response.py", line 186, in validate_response_body
    validate_schema_object(response_body_spec, response_value)
  File "/nail/live/yelp/virtualenv_run/lib/python2.7/site-packages/bravado_core/validate.py", line 21, in validate_schema_object
    obj_type = spec['type']
KeyError: 'type'

From the spec it does not look like 'type' key presence should be mandated. Instead it should be defaulted to 'object' is properties field is non-empty imo. Also, swagger-converter does not add type: object to any of the definitions after conversions.

@prat0318 prat0318 added the bug label Aug 28, 2015
@prat0318
Copy link
Contributor Author

Also, editor.swagger.io's petstore-simple has no type: object for all its definitions.

@prat0318
Copy link
Contributor Author

As per ron from swagger: it's not mandatory in schema definition, but it is highly recommended (I'll fix the examples). Not having a type has an unexpected meaning to most users.

@analogue analogue assigned analogue and unassigned analogue Sep 11, 2015
@analogue
Copy link
Contributor

The fix for #35 makes it so 'type' is required. The rationale being, definitions split up across multiple files are a little more involved to go track down and check for compliance. This is no longer just a matter of checking #/definitions in the root spec.

@msander
Copy link

msander commented Dec 8, 2015

Why can't we just guess the type based on the given keywords if it is not defined?

http://json-schema.org/latest/json-schema-validation.html

e.g.
properties -> object
items -> array
else -> string

I'm using Restlet Studio for designing my API and it also doesn't generate these 'type' values.
(I already dropped them a mail, but I think there might be more tools which could make problems here)

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

3 participants