File: integrations.py

package info (click to toggle)
python-openapi-core 0.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,104 kB
  • sloc: python: 19,979; makefile: 44
file content (38 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (2)
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
29
30
31
32
33
34
35
36
37
38
"""OpenAPI core unmarshalling processors module"""

from typing import Generic

from openapi_core.app import OpenAPI
from openapi_core.protocols import Request
from openapi_core.protocols import Response
from openapi_core.typing import RequestType
from openapi_core.typing import ResponseType


class ValidationIntegration(Generic[RequestType, ResponseType]):
    def __init__(
        self,
        openapi: OpenAPI,
    ):
        self.openapi = openapi

    def get_openapi_request(self, request: RequestType) -> Request:
        raise NotImplementedError

    def get_openapi_response(self, response: ResponseType) -> Response:
        raise NotImplementedError

    def validate_request(self, request: RequestType) -> None:
        openapi_request = self.get_openapi_request(request)
        self.openapi.validate_request(
            openapi_request,
        )

    def validate_response(
        self,
        request: RequestType,
        response: ResponseType,
    ) -> None:
        openapi_request = self.get_openapi_request(request)
        openapi_response = self.get_openapi_response(response)
        self.openapi.validate_response(openapi_request, openapi_response)