-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathviews.py
More file actions
26 lines (20 loc) · 1008 Bytes
/
views.py
File metadata and controls
26 lines (20 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""OpenAPI core contrib flask views module"""
from flask.views import MethodView
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler
from openapi_core.validation.request import openapi_request_validator
from openapi_core.validation.response import openapi_response_validator
class FlaskOpenAPIView(MethodView):
"""Brings OpenAPI specification validation and unmarshalling for views."""
openapi_errors_handler = FlaskOpenAPIErrorsHandler
def __init__(self, spec):
super().__init__()
self.spec = spec
def dispatch_request(self, *args, **kwargs):
decorator = FlaskOpenAPIViewDecorator(
self.spec,
request_validator=openapi_request_validator,
response_validator=openapi_response_validator,
openapi_errors_handler=self.openapi_errors_handler,
)
return decorator(super().dispatch_request)(*args, **kwargs)