File: views.py

package info (click to toggle)
python-openapi-core 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,008 kB
  • sloc: python: 18,868; makefile: 47
file content (28 lines) | stat: -rw-r--r-- 846 bytes parent folder | download
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
28
"""OpenAPI core contrib flask views module"""

from typing import Any

from flask.views import MethodView

from openapi_core import OpenAPI
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler


class FlaskOpenAPIView(MethodView):
    """Brings OpenAPI specification validation and unmarshalling for views."""

    openapi_errors_handler = FlaskOpenAPIErrorsHandler

    def __init__(self, openapi: OpenAPI):
        super().__init__()

        self.decorator = FlaskOpenAPIViewDecorator(
            openapi,
            errors_handler_cls=self.openapi_errors_handler,
        )

    def dispatch_request(self, *args: Any, **kwargs: Any) -> Any:
        response = self.decorator(super().dispatch_request)(*args, **kwargs)

        return response