2020-01-13 15:37:12 +00:00
|
|
|
"""OpenAPI core contrib flask views module"""
|
|
|
|
from flask.views import MethodView
|
|
|
|
|
|
|
|
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
|
2020-01-26 23:29:19 +00:00
|
|
|
from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler
|
2020-01-13 15:37:12 +00:00
|
|
|
from openapi_core.validation.request.validators import RequestValidator
|
|
|
|
from openapi_core.validation.response.validators import ResponseValidator
|
|
|
|
|
|
|
|
|
|
|
|
class FlaskOpenAPIView(MethodView):
|
|
|
|
"""Brings OpenAPI specification validation and unmarshalling for views."""
|
|
|
|
|
2020-01-26 23:29:19 +00:00
|
|
|
openapi_errors_handler = FlaskOpenAPIErrorsHandler
|
|
|
|
|
|
|
|
def __init__(self, spec):
|
|
|
|
super(FlaskOpenAPIView, self).__init__()
|
|
|
|
self.request_validator = RequestValidator(spec)
|
|
|
|
self.response_validator = ResponseValidator(spec)
|
2020-01-13 15:37:12 +00:00
|
|
|
|
|
|
|
def dispatch_request(self, *args, **kwargs):
|
|
|
|
decorator = FlaskOpenAPIViewDecorator(
|
|
|
|
request_validator=self.request_validator,
|
|
|
|
response_validator=self.response_validator,
|
2020-01-26 23:29:19 +00:00
|
|
|
openapi_errors_handler=self.openapi_errors_handler,
|
2020-01-13 15:37:12 +00:00
|
|
|
)
|
|
|
|
return decorator(super(FlaskOpenAPIView, self).dispatch_request)(
|
|
|
|
*args, **kwargs)
|