Yelp / swagger_spec_validator

Other
104 stars 71 forks source link

swagger_spec failed to validated file type on response. #58

Closed gustavo-freitas-movile closed 7 years ago

gustavo-freitas-movile commented 7 years ago

https://github.com/zalando/connexion/issues/324

Description

When i code my swagger on editor.swagger.io , its work properly. however when i try to run connexion, i got the following execution error:

swagger_spec_validator.common.SwaggerValidationError: {'description': 'Download static files', 'schema': {'description': 'binary file', 'type': 'file'}} is not valid under any of the given schemas

I can not found a good example how to return a file as response. Someone can help me?

Expected bahaviour

paths:
  /download/{filename}:
    get:
      tags:
      - "files"
      description: |
        Download static files
      operationId: "controllers.static_controller.download_get"
      parameters:
      - name: "filename"
        in: "path"
        description: "Issue number"
        required: true
        type: "string"
      responses:
        200:
          description: "Download static files"
          schema:
            description: "binary file"
            type: "file"
            #$ref: "#/definitions/Issue"
        default:
          description: "Unexpected error"
          schema:
            $ref: "#/definitions/Error"
      security:
      - UserSecurity: []

Actual behaviour

ile "/usr/local/lib/python3.5/dist-packages/connexion/app.py", line 149, in add_api
    debug=self.debug)
  File "/usr/local/lib/python3.5/dist-packages/connexion/api.py", line 109, in __init__
    validate_spec(spec)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/validator20.py", line 82, in validate_spec
    http_handlers=http_handlers)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/common.py", line 22, in wrapper
    sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/common.py", line 17, in wrapper
    return method(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/validator20.py", line 125, in validate_json
    cls=Draft4Validator)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/ref_validators.py", line 34, in validate
    instance_cls(schema, *args, **kwargs).validate(instance)
  File "/usr/local/lib/python3.5/dist-packages/jsonschema/validators.py", line 123, in validate
    raise error
swagger_spec_validator.common.SwaggerValidationError: {'description': 'Download static files', 'schema': {'description': 'binary file', 'type': 'file'}} 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']['/download/{filename}']['get']['responses']['200']:
    {'description': 'Download static files',
     'schema': {'description': 'binary file', 'type': 'file'}}

Steps to reproduce

./run.sh 
[2016-10-24 12:40:46 -0200] [8834] [INFO] Starting gunicorn 19.6.0
[2016-10-24 12:40:46 -0200] [8834] [INFO] Listening at: http://0.0.0.0:8080 (8834)
[2016-10-24 12:40:46 -0200] [8834] [INFO] Using worker: gevent
[2016-10-24 12:40:46 -0200] [8837] [INFO] Booting worker with pid: 8837
[2016-10-24 12:40:46 -0200] [8838] [INFO] Booting worker with pid: 8838
[2016-10-24 12:40:46 -0200] [8837] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/common.py", line 17, in wrapper
    return method(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/validator20.py", line 125, in validate_json
    cls=Draft4Validator)
  File "/usr/local/lib/python3.5/dist-packages/swagger_spec_validator/ref_validators.py", line 34, in validate
    instance_cls(schema, *args, **kwargs).validate(instance)
  File "/usr/local/lib/python3.5/dist-packages/jsonschema/validators.py", line 123, in validate
    raise error
jsonschema.exceptions.ValidationError: {'description': 'Download static files', 'schema': {'description': 'binary file', 'type': 'file'}} 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']['/download/{filename}']['get']['responses']['200']:
    {'description': 'Download static files',
     'schema': {'description': 'binary file', 'type': 'file'}}

During handling of the above exception, another exception occurred:

cat run.sh 
#gunicorn -w 9 -b 0.0.0.0:8080 wsgi -t 3600 -k gevent
gunicorn -w 2 -b 0.0.0.0:8080 wsgi -t 3600 -k gevent
#gunicorn -w 2 -b 0.0.0.0:8080 wsgi -t 3600 -k gevent

#celery -A wsgi worker --loglevel=info

my wsgi.py

if __name__ == "__main__":
    #app_run()
    application.run() #(threaded=True)
    #application.run(host='0.0.0.0',port=8080)

Additional info:

pip3 show connexion | grep "^Version:" Version: 1.0.129 python3 --version Python 3.5.2

Output of the commands:

gustavo-freitas-movile commented 7 years ago

Someone can help me?

gustavo-freitas-movile commented 7 years ago

https://github.com/ksharenkov/swagger_spec_validator i found someone that fix it :)

Could you please merge it on the master branch ?

dimbleby commented 7 years ago

I think this issue duplicates #50.

Per that one, this is already fixed on master - we just want it to be published.