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

MIME type with period causes validation to fail #63

Open
gward opened this issue Feb 2, 2017 · 1 comment
Open

MIME type with period causes validation to fail #63

gward opened this issue Feb 2, 2017 · 1 comment

Comments

@gward
Copy link

gward commented Feb 2, 2017

Here is a very simple swagger spec, which I created with the Swagger Editor:

$ cat /tmp/swagger.json 
{
    "swagger": "2.0",
    "info": {
        "title": "example",
        "version": "1.0.0"
    },
    "schemes": [
        "https"
    ],
    "produces": [
        "application/vnd.example+json"
    ],
    "paths": {
        "/products": {
            "get": {
                "summary": "stuff",
                "description": "stuff",
                "responses": {
                    "200": {
                        "description": "array of strings",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        },
                        "examples": {
                            "application/vnd.example+json": [
                                "foo",
                                "bar"
                            ]
                        }
                    }
                }
            }
        }
    }
}

If I use swagger_spec_validator on this, it fails:

$ python -c 'import swagger_spec_validator as v; v.validate_spec_url("file:///tmp/swagger.json")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/common.py", line 22, in wrapper
    sys.exc_info()[2])
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/common.py", line 17, in wrapper
    return method(*args, **kwargs)
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/util.py", line 53, in validate_spec_url
    validator.validate_spec(spec_json, spec_url)
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/validator20.py", line 82, in validate_spec
    http_handlers=http_handlers)
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/common.py", line 22, in wrapper
    sys.exc_info()[2])
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/common.py", line 17, in wrapper
    return method(*args, **kwargs)
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/validator20.py", line 125, in validate_json
    cls=Draft4Validator)
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/swagger_spec_validator/ref_validators.py", line 34, in validate
    instance_cls(schema, *args, **kwargs).validate(instance)
  File "/var/lib/venv/tapi/local/lib/python2.7/site-packages/jsonschema/validators.py", line 123, in validate
    raise error
swagger_spec_validator.common.SwaggerValidationError: {u'examples': {u'application/vnd.example+json': [u'foo', u'bar']}, u'description': u'array of strings', u'schema': {u'items': {u'type': u'string'}, u'type': u'array'}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']['properties']['responses']['patternProperties']['^([0-9]{3})$|^(default)$']:
    {'oneOf': [{'$ref': '#/definitions/response'},
               {'$ref': '#/definitions/jsonReference'}]}

On instance['paths'][u'/products']['get']['responses'][u'200']:
    {u'description': u'array of strings',
     u'examples': {u'application/vnd.example+json': [u'foo', u'bar']},
     u'schema': {u'items': {u'type': u'string'}, u'type': u'array'}}

It appears that the reason for the failure is the period in the MIME type used in the examples object. If I remove the period:

--- swagger.json.orig	2017-02-02 11:55:49.539545943 -0500
+++ swagger.json	2017-02-02 11:55:53.799656809 -0500
@@ -25,7 +25,7 @@
                             }
                         },
                         "examples": {
-                            "application/vnd.example+json": [
+                            "application/vndexample+json": [
                                 "foo",
                                 "bar"
                             ]

then validation passes:

$ python -c 'import swagger_spec_validator as v; v.validate_spec_url("file:///tmp/swagger.json")'
@gward
Copy link
Author

gward commented Feb 2, 2017

I'm following https://tools.ietf.org/html/rfc6838#section-4.2 for naming of vendor media types here.

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