Closed
Description
For a flask app, the openapi decorator is failing to provide a response to the flask decorator. Running the following minimum reproducible example, basically taken directly from the documentation:
application/__init__.py
:
from flask import Flask
from openapi_core import Spec
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
app = Flask(__name__)
spec = Spec.from_file_path("openapi_alt.yml")
openapi = FlaskOpenAPIViewDecorator.from_spec(spec)
@app.route('/home')
@openapi
def home():
pass
openapi_alt.yml
:
openapi: 3.1.0
info:
title: OSS IRI rewrite
description: This api will specify the different ways to call the IRI tool
version: 0.1.0
paths:
/home:
get:
responses:
"200":
content:
text/html:
schema:
type: string
by running the command:
flask --app application run
then curling:
curl localhost:5000/home
produces the following error:
[2023-01-25 14:54:26,776] ERROR in app: Exception on /home [GET]
Traceback (most recent call last):
File "/home/connor/.local/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/home/connor/.local/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/connor/.local/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/home/connor/.local/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/contrib/flask/decorators.py", line 57, in decorated
response_result = self.process_response(
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/validation/processors.py", line 28, in process_response
return self.response_validator.validate(spec, request, response)
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/validation/response/proxies.py", line 38, in validate
return validator.validate(spec, request, response, base_url=base_url)
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/validation/response/validators.py", line 234, in validate
operation_response = self._find_operation_response(
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/validation/response/validators.py", line 63, in _find_operation_response
return self._get_operation_response(operation, response)
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/validation/response/validators.py", line 71, in _get_operation_response
return finder.find(str(response.status_code))
File "/home/connor/.local/lib/python3.10/site-packages/openapi_core/contrib/werkzeug/responses.py", line 16, in status_code
return self.response._status_code
AttributeError: 'NoneType' object has no attribute '_status_code'
It seems that combining the openapi decorator with the flask decorator (exactly as shown in the docs) causes the flask decorator to only get the output of the routing function, rather than a response object which wraps that output.
Metadata
Metadata
Assignees
Labels
No labels