-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathviews.py
27 lines (19 loc) · 906 Bytes
/
views.py
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
27
"""OpenAPI core contrib flask views module"""
from typing import Any
from flask.views import MethodView
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler
from openapi_core.spec import Spec
class FlaskOpenAPIView(MethodView):
"""Brings OpenAPI specification validation and unmarshalling for views."""
openapi_errors_handler = FlaskOpenAPIErrorsHandler
def __init__(self, spec: Spec, **unmarshaller_kwargs: Any):
super().__init__()
self.spec = spec
self.decorator = FlaskOpenAPIViewDecorator(
self.spec,
openapi_errors_handler=self.openapi_errors_handler,
**unmarshaller_kwargs,
)
def dispatch_request(self, *args: Any, **kwargs: Any) -> Any:
return self.decorator(super().dispatch_request)(*args, **kwargs)