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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
|
"""OpenAPI core app module"""
from functools import cached_property
from pathlib import Path
from typing import Optional
from jsonschema._utils import Unset
from jsonschema.validators import _UNSET
from jsonschema_path import SchemaPath
from jsonschema_path.handlers.protocols import SupportsRead
from jsonschema_path.typing import Schema
from openapi_spec_validator import validate
from openapi_spec_validator.validation.exceptions import ValidatorDetectError
from openapi_spec_validator.versions.datatypes import SpecVersion
from openapi_spec_validator.versions.exceptions import OpenAPIVersionNotFound
from openapi_spec_validator.versions.shortcuts import get_spec_version
from typing_extensions import Annotated
from typing_extensions import Doc
from openapi_core.configurations import Config
from openapi_core.exceptions import SpecError
from openapi_core.protocols import Request
from openapi_core.protocols import Response
from openapi_core.protocols import WebhookRequest
from openapi_core.types import AnyRequest
from openapi_core.unmarshalling.request import (
UNMARSHALLERS as REQUEST_UNMARSHALLERS,
)
from openapi_core.unmarshalling.request import (
WEBHOOK_UNMARSHALLERS as WEBHOOK_REQUEST_UNMARSHALLERS,
)
from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult
from openapi_core.unmarshalling.request.protocols import RequestUnmarshaller
from openapi_core.unmarshalling.request.protocols import (
WebhookRequestUnmarshaller,
)
from openapi_core.unmarshalling.request.types import RequestUnmarshallerType
from openapi_core.unmarshalling.request.types import (
WebhookRequestUnmarshallerType,
)
from openapi_core.unmarshalling.response import (
UNMARSHALLERS as RESPONSE_UNMARSHALLERS,
)
from openapi_core.unmarshalling.response import (
WEBHOOK_UNMARSHALLERS as WEBHOOK_RESPONSE_UNMARSHALLERS,
)
from openapi_core.unmarshalling.response.datatypes import (
ResponseUnmarshalResult,
)
from openapi_core.unmarshalling.response.protocols import ResponseUnmarshaller
from openapi_core.unmarshalling.response.protocols import (
WebhookResponseUnmarshaller,
)
from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType
from openapi_core.unmarshalling.response.types import (
WebhookResponseUnmarshallerType,
)
from openapi_core.validation.request import VALIDATORS as REQUEST_VALIDATORS
from openapi_core.validation.request import (
WEBHOOK_VALIDATORS as WEBHOOK_REQUEST_VALIDATORS,
)
from openapi_core.validation.request.protocols import RequestValidator
from openapi_core.validation.request.protocols import WebhookRequestValidator
from openapi_core.validation.request.types import RequestValidatorType
from openapi_core.validation.request.types import WebhookRequestValidatorType
from openapi_core.validation.response import VALIDATORS as RESPONSE_VALIDATORS
from openapi_core.validation.response import (
WEBHOOK_VALIDATORS as WEBHOOK_RESPONSE_VALIDATORS,
)
from openapi_core.validation.response.protocols import ResponseValidator
from openapi_core.validation.response.protocols import WebhookResponseValidator
from openapi_core.validation.response.types import ResponseValidatorType
from openapi_core.validation.response.types import WebhookResponseValidatorType
class OpenAPI:
"""`OpenAPI` application class, the main entrypoint class for OpenAPI-core.
OpenAPI can be created in multiple ways: from existing memory data or from storage such as local disk via ``from_*()`` APIs
Read more information, in the
[OpenAPI-core docs for First Steps](https://openapi-core.readthedocs.io/#first-steps).
Examples:
You can import the OpenAPI class directly from openapi_core:
Create an OpenAPI from a dictionary:
```python
from openapi_core import OpenAPI
app = OpenAPI.from_dict(spec)
```
Create an OpenAPI from a path object:
```python
from openapi_core import OpenAPI
app = OpenAPI.from_path(path)
```
Create an OpenAPI from a file path:
```python
from openapi_core import OpenAPI
app = OpenAPI.from_file_path('spec.yaml')
```
Create an OpenAPI from a file object:
```python
from openapi_core import OpenAPI
with open('spec.yaml') as f:
app = OpenAPI.from_file(f)
```
"""
def __init__(
self,
spec: Annotated[
SchemaPath,
Doc(
"""
OpenAPI specification schema path object.
"""
),
],
config: Annotated[
Optional[Config],
Doc(
"""
Configuration object for the OpenAPI application.
"""
),
] = None,
):
if not isinstance(spec, SchemaPath):
raise TypeError("'spec' argument is not type of SchemaPath")
self.spec = spec
self.config = config or Config()
self.check_spec()
@classmethod
def from_dict(
cls,
data: Annotated[
Schema,
Doc(
"""
Dictionary representing the OpenAPI specification.
"""
),
],
config: Annotated[
Optional[Config],
Doc(
"""
Configuration object for the OpenAPI application.
"""
),
] = None,
base_uri: Annotated[
str,
Doc(
"""
Base URI for the OpenAPI specification.
"""
),
] = "",
) -> "OpenAPI":
"""Creates an `OpenAPI` from a dictionary.
Example:
```python
from openapi_core import OpenAPI
app = OpenAPI.from_dict(spec)
```
Returns:
OpenAPI: An instance of the OpenAPI class.
"""
sp = SchemaPath.from_dict(data, base_uri=base_uri)
return cls(sp, config=config)
@classmethod
def from_path(
cls,
path: Annotated[
Path,
Doc(
"""
Path object representing the OpenAPI specification file.
"""
),
],
config: Annotated[
Optional[Config],
Doc(
"""
Configuration object for the OpenAPI application.
"""
),
] = None,
) -> "OpenAPI":
"""Creates an `OpenAPI` from a [Path object](https://docs.python.org/3/library/pathlib.html#pathlib.Path).
Example:
```python
from openapi_core import OpenAPI
app = OpenAPI.from_path(path)
```
Returns:
OpenAPI: An instance of the OpenAPI class.
"""
sp = SchemaPath.from_path(path)
return cls(sp, config=config)
@classmethod
def from_file_path(
cls,
file_path: Annotated[
str,
Doc(
"""
File path string representing the OpenAPI specification file.
"""
),
],
config: Annotated[
Optional[Config],
Doc(
"""
Configuration object for the OpenAPI application.
"""
),
] = None,
) -> "OpenAPI":
"""Creates an `OpenAPI` from a file path string.
Example:
```python
from openapi_core import OpenAPI
app = OpenAPI.from_file_path('spec.yaml')
```
Returns:
OpenAPI: An instance of the OpenAPI class.
"""
sp = SchemaPath.from_file_path(file_path)
return cls(sp, config=config)
@classmethod
def from_file(
cls,
fileobj: Annotated[
SupportsRead,
Doc(
"""
File object representing the OpenAPI specification file.
"""
),
],
config: Annotated[
Optional[Config],
Doc(
"""
Configuration object for the OpenAPI application.
"""
),
] = None,
base_uri: Annotated[
str,
Doc(
"""
Base URI for the OpenAPI specification.
"""
),
] = "",
) -> "OpenAPI":
"""Creates an `OpenAPI` from a [file object](https://docs.python.org/3/glossary.html#term-file-object).
Example:
```python
from openapi_core import OpenAPI
with open('spec.yaml') as f:
app = OpenAPI.from_file(f)
```
Returns:
OpenAPI: An instance of the OpenAPI class.
"""
sp = SchemaPath.from_file(fileobj, base_uri=base_uri)
return cls(sp, config=config)
def _get_version(self) -> SpecVersion:
try:
return get_spec_version(self.spec.contents())
# backward compatibility
except OpenAPIVersionNotFound:
raise SpecError("Spec schema version not detected")
def check_spec(self) -> None:
if self.config.spec_validator_cls is None:
return
cls = None
if self.config.spec_validator_cls is not _UNSET:
cls = self.config.spec_validator_cls
try:
validate(
self.spec.contents(),
base_uri=self.config.spec_base_uri
or self.spec.accessor.resolver._base_uri, # type: ignore[attr-defined]
cls=cls,
)
except ValidatorDetectError:
raise SpecError("spec not detected")
@property
def version(self) -> SpecVersion:
return self._get_version()
@cached_property
def request_validator_cls(self) -> Optional[RequestValidatorType]:
if not isinstance(self.config.request_validator_cls, Unset):
return self.config.request_validator_cls
return REQUEST_VALIDATORS.get(self.version)
@cached_property
def response_validator_cls(self) -> Optional[ResponseValidatorType]:
if not isinstance(self.config.response_validator_cls, Unset):
return self.config.response_validator_cls
return RESPONSE_VALIDATORS.get(self.version)
@cached_property
def webhook_request_validator_cls(
self,
) -> Optional[WebhookRequestValidatorType]:
if not isinstance(self.config.webhook_request_validator_cls, Unset):
return self.config.webhook_request_validator_cls
return WEBHOOK_REQUEST_VALIDATORS.get(self.version)
@cached_property
def webhook_response_validator_cls(
self,
) -> Optional[WebhookResponseValidatorType]:
if not isinstance(self.config.webhook_response_validator_cls, Unset):
return self.config.webhook_response_validator_cls
return WEBHOOK_RESPONSE_VALIDATORS.get(self.version)
@cached_property
def request_unmarshaller_cls(self) -> Optional[RequestUnmarshallerType]:
if not isinstance(self.config.request_unmarshaller_cls, Unset):
return self.config.request_unmarshaller_cls
return REQUEST_UNMARSHALLERS.get(self.version)
@cached_property
def response_unmarshaller_cls(self) -> Optional[ResponseUnmarshallerType]:
if not isinstance(self.config.response_unmarshaller_cls, Unset):
return self.config.response_unmarshaller_cls
return RESPONSE_UNMARSHALLERS.get(self.version)
@cached_property
def webhook_request_unmarshaller_cls(
self,
) -> Optional[WebhookRequestUnmarshallerType]:
if not isinstance(self.config.webhook_request_unmarshaller_cls, Unset):
return self.config.webhook_request_unmarshaller_cls
return WEBHOOK_REQUEST_UNMARSHALLERS.get(self.version)
@cached_property
def webhook_response_unmarshaller_cls(
self,
) -> Optional[WebhookResponseUnmarshallerType]:
if not isinstance(
self.config.webhook_response_unmarshaller_cls, Unset
):
return self.config.webhook_response_unmarshaller_cls
return WEBHOOK_RESPONSE_UNMARSHALLERS.get(self.version)
@cached_property
def request_validator(self) -> RequestValidator:
if self.request_validator_cls is None:
raise SpecError("Validator class not found")
return self.request_validator_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
security_provider_factory=self.config.security_provider_factory,
)
@cached_property
def response_validator(self) -> ResponseValidator:
if self.response_validator_cls is None:
raise SpecError("Validator class not found")
return self.response_validator_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
)
@cached_property
def webhook_request_validator(self) -> WebhookRequestValidator:
if self.webhook_request_validator_cls is None:
raise SpecError("Validator class not found")
return self.webhook_request_validator_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.webhook_path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
security_provider_factory=self.config.security_provider_factory,
)
@cached_property
def webhook_response_validator(self) -> WebhookResponseValidator:
if self.webhook_response_validator_cls is None:
raise SpecError("Validator class not found")
return self.webhook_response_validator_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.webhook_path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
)
@cached_property
def request_unmarshaller(self) -> RequestUnmarshaller:
if self.request_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
return self.request_unmarshaller_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
security_provider_factory=self.config.security_provider_factory,
schema_unmarshallers_factory=self.config.schema_unmarshallers_factory,
extra_format_unmarshallers=self.config.extra_format_unmarshallers,
)
@cached_property
def response_unmarshaller(self) -> ResponseUnmarshaller:
if self.response_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
return self.response_unmarshaller_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
schema_unmarshallers_factory=self.config.schema_unmarshallers_factory,
extra_format_unmarshallers=self.config.extra_format_unmarshallers,
)
@cached_property
def webhook_request_unmarshaller(self) -> WebhookRequestUnmarshaller:
if self.webhook_request_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
return self.webhook_request_unmarshaller_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.webhook_path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
security_provider_factory=self.config.security_provider_factory,
schema_unmarshallers_factory=self.config.schema_unmarshallers_factory,
extra_format_unmarshallers=self.config.extra_format_unmarshallers,
)
@cached_property
def webhook_response_unmarshaller(self) -> WebhookResponseUnmarshaller:
if self.webhook_response_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
return self.webhook_response_unmarshaller_cls(
self.spec,
base_url=self.config.server_base_url,
style_deserializers_factory=self.config.style_deserializers_factory,
media_type_deserializers_factory=self.config.media_type_deserializers_factory,
schema_casters_factory=self.config.schema_casters_factory,
schema_validators_factory=self.config.schema_validators_factory,
path_finder_cls=self.config.webhook_path_finder_cls,
spec_validator_cls=self.config.spec_validator_cls,
extra_format_validators=self.config.extra_format_validators,
extra_media_type_deserializers=self.config.extra_media_type_deserializers,
schema_unmarshallers_factory=self.config.schema_unmarshallers_factory,
extra_format_unmarshallers=self.config.extra_format_unmarshallers,
)
def validate_request(
self,
request: Annotated[
AnyRequest,
Doc(
"""
Request object to be validated.
"""
),
],
) -> None:
"""Validates the given request object.
Args:
request (AnyRequest): Request object to be validated.
Raises:
TypeError: If the request object is not of the expected type.
SpecError: If the validator class is not found.
"""
if isinstance(request, WebhookRequest):
self.validate_webhook_request(request)
else:
self.validate_apicall_request(request)
def validate_response(
self,
request: Annotated[
AnyRequest,
Doc(
"""
Request object associated with the response.
"""
),
],
response: Annotated[
Response,
Doc(
"""
Response object to be validated.
"""
),
],
) -> None:
"""Validates the given response object associated with the request.
Args:
request (AnyRequest): Request object associated with the response.
response (Response): Response object to be validated.
Raises:
TypeError: If the request or response object is not of the expected type.
SpecError: If the validator class is not found.
"""
if isinstance(request, WebhookRequest):
self.validate_webhook_response(request, response)
else:
self.validate_apicall_response(request, response)
def validate_apicall_request(
self,
request: Annotated[
Request,
Doc(
"""
API call request object to be validated.
"""
),
],
) -> None:
if not isinstance(request, Request):
raise TypeError("'request' argument is not type of Request")
self.request_validator.validate(request)
def validate_apicall_response(
self,
request: Annotated[
Request,
Doc(
"""
API call request object associated with the response.
"""
),
],
response: Annotated[
Response,
Doc(
"""
API call response object to be validated.
"""
),
],
) -> None:
if not isinstance(request, Request):
raise TypeError("'request' argument is not type of Request")
if not isinstance(response, Response):
raise TypeError("'response' argument is not type of Response")
self.response_validator.validate(request, response)
def validate_webhook_request(
self,
request: Annotated[
WebhookRequest,
Doc(
"""
Webhook request object to be validated.
"""
),
],
) -> None:
if not isinstance(request, WebhookRequest):
raise TypeError("'request' argument is not type of WebhookRequest")
self.webhook_request_validator.validate(request)
def validate_webhook_response(
self,
request: Annotated[
WebhookRequest,
Doc(
"""
Webhook request object associated with the response.
"""
),
],
response: Annotated[
Response,
Doc(
"""
Webhook response object to be validated.
"""
),
],
) -> None:
if not isinstance(request, WebhookRequest):
raise TypeError("'request' argument is not type of WebhookRequest")
if not isinstance(response, Response):
raise TypeError("'response' argument is not type of Response")
self.webhook_response_validator.validate(request, response)
def unmarshal_request(
self,
request: Annotated[
AnyRequest,
Doc(
"""
Request object to be unmarshalled.
"""
),
],
) -> RequestUnmarshalResult:
"""Unmarshals the given request object.
Args:
request (AnyRequest): Request object to be unmarshalled.
Returns:
RequestUnmarshalResult: The result of the unmarshalling process.
Raises:
TypeError: If the request object is not of the expected type.
SpecError: If the unmarshaller class is not found.
"""
if isinstance(request, WebhookRequest):
return self.unmarshal_webhook_request(request)
else:
return self.unmarshal_apicall_request(request)
def unmarshal_response(
self,
request: Annotated[
AnyRequest,
Doc(
"""
Request object associated with the response.
"""
),
],
response: Annotated[
Response,
Doc(
"""
Response object to be unmarshalled.
"""
),
],
) -> ResponseUnmarshalResult:
"""Unmarshals the given response object associated with the request.
Args:
request (AnyRequest): Request object associated with the response.
response (Response): Response object to be unmarshalled.
Returns:
ResponseUnmarshalResult: The result of the unmarshalling process.
Raises:
TypeError: If the request or response object is not of the expected type.
SpecError: If the unmarshaller class is not found.
"""
if isinstance(request, WebhookRequest):
return self.unmarshal_webhook_response(request, response)
else:
return self.unmarshal_apicall_response(request, response)
def unmarshal_apicall_request(
self,
request: Annotated[
Request,
Doc(
"""
API call request object to be unmarshalled.
"""
),
],
) -> RequestUnmarshalResult:
if not isinstance(request, Request):
raise TypeError("'request' argument is not type of Request")
return self.request_unmarshaller.unmarshal(request)
def unmarshal_apicall_response(
self,
request: Annotated[
Request,
Doc(
"""
API call request object associated with the response.
"""
),
],
response: Annotated[
Response,
Doc(
"""
API call response object to be unmarshalled.
"""
),
],
) -> ResponseUnmarshalResult:
if not isinstance(request, Request):
raise TypeError("'request' argument is not type of Request")
if not isinstance(response, Response):
raise TypeError("'response' argument is not type of Response")
return self.response_unmarshaller.unmarshal(request, response)
def unmarshal_webhook_request(
self,
request: Annotated[
WebhookRequest,
Doc(
"""
Webhook request object to be unmarshalled.
"""
),
],
) -> RequestUnmarshalResult:
if not isinstance(request, WebhookRequest):
raise TypeError("'request' argument is not type of WebhookRequest")
return self.webhook_request_unmarshaller.unmarshal(request)
def unmarshal_webhook_response(
self,
request: Annotated[
WebhookRequest,
Doc(
"""
Webhook request object associated with the response.
"""
),
],
response: Annotated[
Response,
Doc(
"""
Webhook response object to be unmarshalled.
"""
),
],
) -> ResponseUnmarshalResult:
if not isinstance(request, WebhookRequest):
raise TypeError("'request' argument is not type of WebhookRequest")
if not isinstance(response, Response):
raise TypeError("'response' argument is not type of Response")
return self.webhook_response_unmarshaller.unmarshal(request, response)
|