Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path finder cls configuration #797

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions openapi_core/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""OpenAPI core app module"""

from functools import cached_property
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -142,55 +143,55 @@ def check_spec(self) -> None:
def version(self) -> SpecVersion:
return self._get_version()

@property
@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)

@property
@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)

@property
@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)

@property
@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)

@property
@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)

@property
@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)

@property
@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)

@property
@cached_property
def webhook_response_unmarshaller_cls(
self,
) -> Optional[WebhookResponseUnmarshallerType]:
Expand All @@ -200,7 +201,7 @@ def webhook_response_unmarshaller_cls(
return self.config.webhook_response_unmarshaller_cls
return WEBHOOK_RESPONSE_UNMARSHALLERS.get(self.version)

@property
@cached_property
def request_validator(self) -> RequestValidator:
if self.request_validator_cls is None:
raise SpecError("Validator class not found")
Expand All @@ -211,13 +212,14 @@ def request_validator(self) -> RequestValidator:
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,
)

@property
@cached_property
def response_validator(self) -> ResponseValidator:
if self.response_validator_cls is None:
raise SpecError("Validator class not found")
Expand All @@ -228,12 +230,13 @@ def response_validator(self) -> ResponseValidator:
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,
)

@property
@cached_property
def webhook_request_validator(self) -> WebhookRequestValidator:
if self.webhook_request_validator_cls is None:
raise SpecError("Validator class not found")
Expand All @@ -244,13 +247,14 @@ def webhook_request_validator(self) -> WebhookRequestValidator:
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,
)

@property
@cached_property
def webhook_response_validator(self) -> WebhookResponseValidator:
if self.webhook_response_validator_cls is None:
raise SpecError("Validator class not found")
Expand All @@ -261,12 +265,13 @@ def webhook_response_validator(self) -> WebhookResponseValidator:
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,
)

@property
@cached_property
def request_unmarshaller(self) -> RequestUnmarshaller:
if self.request_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
Expand All @@ -277,6 +282,7 @@ def request_unmarshaller(self) -> RequestUnmarshaller:
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,
Expand All @@ -285,7 +291,7 @@ def request_unmarshaller(self) -> RequestUnmarshaller:
extra_format_unmarshallers=self.config.extra_format_unmarshallers,
)

@property
@cached_property
def response_unmarshaller(self) -> ResponseUnmarshaller:
if self.response_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
Expand All @@ -296,14 +302,15 @@ def response_unmarshaller(self) -> ResponseUnmarshaller:
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,
)

@property
@cached_property
def webhook_request_unmarshaller(self) -> WebhookRequestUnmarshaller:
if self.webhook_request_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
Expand All @@ -314,6 +321,7 @@ def webhook_request_unmarshaller(self) -> WebhookRequestUnmarshaller:
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,
Expand All @@ -322,7 +330,7 @@ def webhook_request_unmarshaller(self) -> WebhookRequestUnmarshaller:
extra_format_unmarshallers=self.config.extra_format_unmarshallers,
)

@property
@cached_property
def webhook_response_unmarshaller(self) -> WebhookResponseUnmarshaller:
if self.webhook_response_unmarshaller_cls is None:
raise SpecError("Unmarshaller class not found")
Expand All @@ -333,6 +341,7 @@ def webhook_response_unmarshaller(self) -> WebhookResponseUnmarshaller:
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,
Expand Down
7 changes: 7 additions & 0 deletions openapi_core/templating/paths/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from openapi_core.templating.paths.finders import APICallPathFinder
from openapi_core.templating.paths.finders import WebhookPathFinder

__all__ = [
"APICallPathFinder",
"WebhookPathFinder",
]
Loading