-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathintegrations.py
38 lines (30 loc) · 1.16 KB
/
integrations.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
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)