Yelp / swagger_spec_validator

Other
104 stars 71 forks source link

Responses object schema rejects file type #46

Closed chriscoomber closed 8 years ago

chriscoomber commented 8 years ago

The following swagger spec json is deemed invalid (by the latest master):

{
    "swagger": "2.0",
    "info": {
        "version": "0.1",
        "title": "Avatar Downloader API"
    },
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/avatars/{avatar_id}": {
            "get": {
                "summary": "Get an avatar",
                "operationId": "mycontroller.get_avatar",
                "produces": [
                    "application/octet-stream"
                ],
                "parameters": [
                    {
                        "name": "avatar_id",
                        "in": "path",
                        "description": "Avatar's unique identifier",
                        "required": true,
                        "type": "string",
                        "pattern": "^[a-zA-Z0-9-_]+$"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Avatar file",
                        "schema": {
                            "type": "file"
                        }
                    },
                    "404": {
                        "description": "Avatar does not exist"
                    }
                }
            }
        }
    }
}

This is due to the "file" type in the response schema:

swagger_spec_validator.common.SwaggerValidationError: {u'description': u'Avatar file', u'schema': {u'type': u'file'}} is not valid under any of the given schemas

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

On instance[u'paths'][u'/avatars/{avatar_id}'][u'get'][u'responses'][u'200']:
    {u'description': u'Avatar file', u'schema': {u'type': u'file'}}

I think this is wrong because http://editor.swagger.io/ deems it valid, and the spec http://swagger.io/specification/#responseObject seems to say this is allowed.

chriscoomber commented 8 years ago

My bad, I was mistakenly using the latest published version, not master (which doesn't have this bug).