Skip to content

Remove deprecated features #598

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

Merged
merged 1 commit into from
Jun 18, 2023
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
20 changes: 0 additions & 20 deletions openapi_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,16 @@
from openapi_core.shortcuts import validate_webhook_request
from openapi_core.shortcuts import validate_webhook_response
from openapi_core.spec import Spec
from openapi_core.unmarshalling.request import RequestValidator
from openapi_core.unmarshalling.request import V3RequestUnmarshaller
from openapi_core.unmarshalling.request import V3WebhookRequestUnmarshaller
from openapi_core.unmarshalling.request import V30RequestUnmarshaller
from openapi_core.unmarshalling.request import V31RequestUnmarshaller
from openapi_core.unmarshalling.request import V31WebhookRequestUnmarshaller
from openapi_core.unmarshalling.request import openapi_request_validator
from openapi_core.unmarshalling.request import openapi_v3_request_validator
from openapi_core.unmarshalling.request import openapi_v30_request_validator
from openapi_core.unmarshalling.request import openapi_v31_request_validator
from openapi_core.unmarshalling.response import ResponseValidator
from openapi_core.unmarshalling.response import V3ResponseUnmarshaller
from openapi_core.unmarshalling.response import V3WebhookResponseUnmarshaller
from openapi_core.unmarshalling.response import V30ResponseUnmarshaller
from openapi_core.unmarshalling.response import V31ResponseUnmarshaller
from openapi_core.unmarshalling.response import V31WebhookResponseUnmarshaller
from openapi_core.unmarshalling.response import openapi_response_validator
from openapi_core.unmarshalling.response import openapi_v3_response_validator
from openapi_core.unmarshalling.response import openapi_v30_response_validator
from openapi_core.unmarshalling.response import openapi_v31_response_validator
from openapi_core.validation.request import V3RequestValidator
from openapi_core.validation.request import V3WebhookRequestValidator
from openapi_core.validation.request import V30RequestValidator
Expand Down Expand Up @@ -83,14 +73,4 @@
"V3ResponseValidator",
"V3WebhookRequestValidator",
"V3WebhookResponseValidator",
"RequestValidator",
"ResponseValidator",
"openapi_v3_request_validator",
"openapi_v30_request_validator",
"openapi_v31_request_validator",
"openapi_request_validator",
"openapi_v3_response_validator",
"openapi_v30_response_validator",
"openapi_v31_response_validator",
"openapi_response_validator",
]
14 changes: 0 additions & 14 deletions openapi_core/deserializing/media_types/factories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings
from typing import Dict
from typing import Optional

from openapi_core.deserializing.media_types.datatypes import (
Expand All @@ -17,20 +15,10 @@ class MediaTypeDeserializersFactory:
def __init__(
self,
media_type_deserializers: Optional[MediaTypeDeserializersDict] = None,
custom_deserializers: Optional[MediaTypeDeserializersDict] = None,
):
if media_type_deserializers is None:
media_type_deserializers = {}
self.media_type_deserializers = media_type_deserializers
if custom_deserializers is None:
custom_deserializers = {}
else:
warnings.warn(
"custom_deserializers is deprecated. "
"Use extra_media_type_deserializers.",
DeprecationWarning,
)
self.custom_deserializers = custom_deserializers

def create(
self,
Expand All @@ -53,8 +41,6 @@ def get_deserializer_callable(
mimetype: str,
extra_media_type_deserializers: MediaTypeDeserializersDict,
) -> Optional[DeserializerCallable]:
if mimetype in self.custom_deserializers:
return self.custom_deserializers[mimetype]
if mimetype in extra_media_type_deserializers:
return extra_media_type_deserializers[mimetype]
return self.media_type_deserializers.get(mimetype)
97 changes: 0 additions & 97 deletions openapi_core/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""OpenAPI core shortcuts module"""
import warnings
from typing import Any
from typing import Dict
from typing import Optional
from typing import Union

from lazy_object_proxy import Proxy

from openapi_core.exceptions import SpecError
from openapi_core.finders import SpecClasses
from openapi_core.finders import SpecFinder
Expand All @@ -23,9 +20,6 @@
from openapi_core.unmarshalling.request.protocols import (
WebhookRequestUnmarshaller,
)
from openapi_core.unmarshalling.request.proxies import (
SpecRequestValidatorProxy,
)
from openapi_core.unmarshalling.request.types import AnyRequestUnmarshallerType
from openapi_core.unmarshalling.request.types import RequestUnmarshallerType
from openapi_core.unmarshalling.request.types import (
Expand All @@ -41,9 +35,6 @@
from openapi_core.unmarshalling.response.protocols import (
WebhookResponseUnmarshaller,
)
from openapi_core.unmarshalling.response.proxies import (
SpecResponseValidatorProxy,
)
from openapi_core.unmarshalling.response.types import (
AnyResponseUnmarshallerType,
)
Expand Down Expand Up @@ -287,56 +278,14 @@ def validate_request(
request: AnyRequest,
spec: Spec,
base_url: Optional[str] = None,
validator: Optional[SpecRequestValidatorProxy] = None,
cls: Optional[AnyRequestValidatorType] = None,
**validator_kwargs: Any,
) -> Optional[RequestUnmarshalResult]:
if isinstance(spec, (Request, WebhookRequest)) and isinstance(
request, Spec
):
warnings.warn(
"spec parameter as a first argument is deprecated. "
"Move it to second argument instead.",
DeprecationWarning,
)
request, spec = spec, request

if not isinstance(request, (Request, WebhookRequest)):
raise TypeError("'request' argument is not type of (Webhook)Request")
if not isinstance(spec, Spec):
raise TypeError("'spec' argument is not type of Spec")

if validator is not None and isinstance(request, Request):
warnings.warn(
"validator parameter is deprecated. Use cls instead.",
DeprecationWarning,
)
result = validator.validate(spec, request, base_url=base_url)
result.raise_for_errors()
return result

# redirect to unmarshaller for backward compatibility
if cls is None or issubclass(
cls, (RequestUnmarshaller, WebhookRequestUnmarshaller)
):
result = unmarshal_request(
request,
spec=spec,
base_url=base_url,
cls=cls,
**validator_kwargs,
)

def return_result() -> RequestUnmarshalResult:
warnings.warn(
"validate_request is deprecated for unmarshalling data "
"and it will not return any result in the future. "
"Use unmarshal_request function instead.",
DeprecationWarning,
)
return result

return Proxy(return_result) # type: ignore
if isinstance(request, WebhookRequest):
if cls is None or issubclass(cls, WebhookRequestValidator):
validate_webhook_request(
Expand Down Expand Up @@ -370,62 +319,16 @@ def validate_response(
response: Union[Response, Request, WebhookRequest],
spec: Union[Spec, Response],
base_url: Optional[str] = None,
validator: Optional[SpecResponseValidatorProxy] = None,
cls: Optional[AnyResponseValidatorType] = None,
**validator_kwargs: Any,
) -> Optional[ResponseUnmarshalResult]:
if (
isinstance(request, Spec)
and isinstance(response, (Request, WebhookRequest))
and isinstance(spec, Response)
):
warnings.warn(
"spec parameter as a first argument is deprecated. "
"Move it to third argument instead.",
DeprecationWarning,
)
args = request, response, spec
spec, request, response = args

if not isinstance(request, (Request, WebhookRequest)):
raise TypeError("'request' argument is not type of (Webhook)Request")
if not isinstance(response, Response):
raise TypeError("'response' argument is not type of Response")
if not isinstance(spec, Spec):
raise TypeError("'spec' argument is not type of Spec")

if validator is not None and isinstance(request, Request):
warnings.warn(
"validator parameter is deprecated. Use cls instead.",
DeprecationWarning,
)
result = validator.validate(spec, request, response, base_url=base_url)
result.raise_for_errors()
return result

# redirect to unmarshaller for backward compatibility
if cls is None or issubclass(
cls, (ResponseUnmarshaller, WebhookResponseUnmarshaller)
):
result = unmarshal_response(
request,
response,
spec=spec,
base_url=base_url,
cls=cls,
**validator_kwargs,
)

def return_result() -> ResponseUnmarshalResult:
warnings.warn(
"validate_response is deprecated for unmarshalling data "
"and it will not return any result in the future. "
"Use unmarshal_response function instead.",
DeprecationWarning,
)
return result

return Proxy(return_result) # type: ignore
if isinstance(request, WebhookRequest):
if cls is None or issubclass(cls, WebhookResponseValidator):
validate_webhook_response(
Expand Down
29 changes: 0 additions & 29 deletions openapi_core/spec/paths.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
import warnings
from typing import Any
from typing import Dict
from typing import Hashable
from typing import Mapping
from typing import Optional
from typing import Type
from typing import TypeVar

from jsonschema_spec import SchemaPath
from jsonschema_spec import default_handlers
from openapi_spec_validator.validation import openapi_spec_validator_proxy
from openapi_spec_validator.validation.protocols import SupportsValidation

TSpec = TypeVar("TSpec", bound="Spec")

SPEC_SEPARATOR = "#"


class Spec(SchemaPath):
@classmethod
def create(
cls: Type[TSpec],
data: Mapping[Hashable, Any],
*args: Any,
url: str = "",
ref_resolver_handlers: Dict[str, Any] = default_handlers,
separator: str = SPEC_SEPARATOR,
validator: Optional[SupportsValidation] = openapi_spec_validator_proxy,
) -> TSpec:
warnings.warn(
"Spec.create method is deprecated. Use Spec.from_dict instead.",
DeprecationWarning,
)

return cls.from_dict(
data,
*args,
spec_url=url,
ref_resolver_handlers=ref_resolver_handlers,
separator=separator,
validator=validator,
)

@classmethod
def from_dict(
cls: Type[TSpec],
Expand Down
36 changes: 0 additions & 36 deletions openapi_core/spec/shortcuts.py

This file was deleted.

48 changes: 2 additions & 46 deletions openapi_core/unmarshalling/request/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
"""OpenAPI core unmarshalling request module"""
from openapi_core.unmarshalling.request.proxies import (
DetectSpecRequestValidatorProxy,
)
from openapi_core.unmarshalling.request.proxies import (
SpecRequestValidatorProxy,
)
from openapi_core.unmarshalling.request.unmarshallers import (
APICallRequestUnmarshaller,
)
from openapi_core.unmarshalling.request.unmarshallers import RequestValidator
from openapi_core.unmarshalling.request.unmarshallers import (
V30RequestUnmarshaller,
)
Expand All @@ -18,49 +8,15 @@
from openapi_core.unmarshalling.request.unmarshallers import (
V31WebhookRequestUnmarshaller,
)
from openapi_core.unmarshalling.schemas import (
oas30_write_schema_unmarshallers_factory,
)
from openapi_core.unmarshalling.schemas import (
oas31_schema_unmarshallers_factory,
)

__all__ = [
"V3RequestUnmarshaller",
"V3WebhookRequestUnmarshaller",
"V30RequestUnmarshaller",
"V31RequestUnmarshaller",
"V31WebhookRequestUnmarshaller",
"RequestValidator",
"openapi_v30_request_validator",
"openapi_v31_request_validator",
"openapi_v3_request_validator",
"openapi_request_validator",
]

# alias to the latest v3 version
V3RequestUnmarshaller = V31RequestUnmarshaller
V3WebhookRequestUnmarshaller = V31WebhookRequestUnmarshaller

# spec validators
openapi_v30_request_validator = SpecRequestValidatorProxy(
APICallRequestUnmarshaller,
schema_unmarshallers_factory=oas30_write_schema_unmarshallers_factory,
deprecated="openapi_v30_request_validator",
use="V30RequestValidator",
)
openapi_v31_request_validator = SpecRequestValidatorProxy(
APICallRequestUnmarshaller,
schema_unmarshallers_factory=oas31_schema_unmarshallers_factory,
deprecated="openapi_v31_request_validator",
use="V31RequestValidator",
)

# spec validators alias to the latest v3 version
openapi_v3_request_validator = openapi_v31_request_validator

# detect version spec
openapi_request_validator = DetectSpecRequestValidatorProxy(
{
("openapi", "3.0"): openapi_v30_request_validator,
("openapi", "3.1"): openapi_v31_request_validator,
},
)
Loading