From 86f8218236190fb403d6daa12336ed52921c455b Mon Sep 17 00:00:00 2001 From: p1c2u Date: Fri, 13 Oct 2023 14:07:24 +0000 Subject: [PATCH] Move to jsonschema-path --- README.rst | 4 +- docs/index.rst | 4 +- docs/integrations.rst | 8 +- openapi_core/casting/schemas/casters.py | 11 +- openapi_core/casting/schemas/factories.py | 5 +- openapi_core/contrib/falcon/middlewares.py | 6 +- openapi_core/contrib/flask/decorators.py | 6 +- openapi_core/contrib/flask/views.py | 4 +- .../deserializing/styles/deserializers.py | 5 +- .../deserializing/styles/factories.py | 5 +- openapi_core/extensions/models/factories.py | 9 +- openapi_core/finders.py | 5 +- openapi_core/schema/parameters.py | 9 +- openapi_core/schema/schemas.py | 4 +- openapi_core/schema/servers.py | 6 +- openapi_core/schema/specs.py | 5 +- openapi_core/security/factories.py | 5 +- openapi_core/security/providers.py | 5 +- openapi_core/shortcuts.py | 76 ++++---- openapi_core/spec/paths.py | 18 +- .../templating/media_types/finders.py | 5 +- openapi_core/templating/paths/finders.py | 10 +- openapi_core/templating/paths/util.py | 1 - openapi_core/templating/responses/finders.py | 7 +- openapi_core/unmarshalling/processors.py | 5 +- .../unmarshalling/request/processors.py | 5 +- .../unmarshalling/request/protocols.py | 7 +- .../unmarshalling/request/unmarshallers.py | 13 +- .../unmarshalling/response/processors.py | 5 +- .../unmarshalling/response/protocols.py | 7 +- .../unmarshalling/response/unmarshallers.py | 9 +- .../unmarshalling/schemas/factories.py | 5 +- .../unmarshalling/schemas/unmarshallers.py | 19 +- openapi_core/unmarshalling/unmarshallers.py | 11 +- openapi_core/validation/processors.py | 5 +- openapi_core/validation/request/exceptions.py | 5 +- openapi_core/validation/request/protocols.py | 7 +- openapi_core/validation/request/validators.py | 27 +-- openapi_core/validation/response/protocols.py | 7 +- .../validation/response/validators.py | 22 ++- openapi_core/validation/schemas/factories.py | 4 +- openapi_core/validation/schemas/validators.py | 14 +- openapi_core/validation/validators.py | 37 ++-- poetry.lock | 19 +- pyproject.toml | 2 +- tests/integration/conftest.py | 9 +- .../data/v3.0/aiohttpproject/openapi.py | 5 +- .../data/v3.0/djangoproject/settings.py | 5 +- .../falcon/data/v3.0/falconproject/openapi.py | 4 +- .../flask/data/v3.0/flaskproject/openapi.py | 4 +- .../data/v3.0/starletteproject/openapi.py | 5 +- tests/integration/schema/test_empty.py | 7 +- tests/integration/schema/test_spec.py | 11 +- .../unmarshalling/test_unmarshallers.py | 180 +++++++++--------- tests/unit/casting/test_schema_casters.py | 6 +- tests/unit/conftest.py | 9 +- .../test_styles_deserializers.py | 8 +- tests/unit/extensions/test_factories.py | 8 +- tests/unit/schema/test_schema_parameters.py | 12 +- tests/unit/security/test_providers.py | 4 +- .../templating/test_media_types_finders.py | 4 +- tests/unit/templating/test_paths_finders.py | 10 +- .../unit/templating/test_responses_finders.py | 4 +- .../test_path_item_params_validator.py | 4 +- .../test_schema_unmarshallers.py | 18 +- .../unit/validation/test_schema_validators.py | 36 ++-- 66 files changed, 424 insertions(+), 387 deletions(-) diff --git a/README.rst b/README.rst index 50c60b50..ed745305 100644 --- a/README.rst +++ b/README.rst @@ -61,9 +61,9 @@ Firstly create your specification object. .. code-block:: python - from openapi_core import Spec + from jsonschema_path import SchemaPath - spec = Spec.from_file_path('openapi.json') + spec = SchemaPath.from_file_path('openapi.json') Now you can use it to validate and unmarshal against requests and/or responses. diff --git a/docs/index.rst b/docs/index.rst index 587156a1..9d309ad8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -49,9 +49,9 @@ Firstly create your specification object. .. code-block:: python - from openapi_core import Spec + from jsonschema_path import SchemaPath - spec = Spec.from_file_path('openapi.json') + spec = SchemaPath.from_file_path('openapi.json') Now you can use it to validate and unmarshal your requests and/or responses. diff --git a/docs/integrations.rst b/docs/integrations.rst index 82422989..e1f8bcb7 100644 --- a/docs/integrations.rst +++ b/docs/integrations.rst @@ -54,14 +54,14 @@ Django can be integrated by middleware. Add ``DjangoOpenAPIMiddleware`` to your :emphasize-lines: 6,9 # settings.py - from openapi_core import Spec + from jsonschema_path import SchemaPath MIDDLEWARE = [ # ... 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', ] - OPENAPI_SPEC = Spec.from_dict(spec_dict) + OPENAPI_SPEC = SchemaPath.from_dict(spec_dict) You can skip response validation process: by setting ``OPENAPI_RESPONSE_CLS`` to ``None`` @@ -69,14 +69,14 @@ You can skip response validation process: by setting ``OPENAPI_RESPONSE_CLS`` to :emphasize-lines: 10 # settings.py - from openapi_core import Spec + from jsonschema_path import SchemaPath MIDDLEWARE = [ # ... 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', ] - OPENAPI_SPEC = Spec.from_dict(spec_dict) + OPENAPI_SPEC = SchemaPath.from_dict(spec_dict) OPENAPI_RESPONSE_CLS = None After that you have access to unmarshal result object with all validated request data from Django view through request object. diff --git a/openapi_core/casting/schemas/casters.py b/openapi_core/casting/schemas/casters.py index d1cd9e00..b62077fc 100644 --- a/openapi_core/casting/schemas/casters.py +++ b/openapi_core/casting/schemas/casters.py @@ -3,16 +3,17 @@ from typing import Callable from typing import List +from jsonschema_path import SchemaPath + from openapi_core.casting.schemas.datatypes import CasterCallable from openapi_core.casting.schemas.exceptions import CastError -from openapi_core.spec import Spec if TYPE_CHECKING: from openapi_core.casting.schemas.factories import SchemaCastersFactory class BaseSchemaCaster: - def __init__(self, schema: Spec): + def __init__(self, schema: SchemaPath): self.schema = schema def __call__(self, value: Any) -> Any: @@ -26,7 +27,7 @@ def cast(self, value: Any) -> Any: class CallableSchemaCaster(BaseSchemaCaster): - def __init__(self, schema: Spec, caster_callable: CasterCallable): + def __init__(self, schema: SchemaPath, caster_callable: CasterCallable): super().__init__(schema) self.caster_callable = caster_callable @@ -43,7 +44,9 @@ def cast(self, value: Any) -> Any: class ComplexCaster(BaseSchemaCaster): - def __init__(self, schema: Spec, casters_factory: "SchemaCastersFactory"): + def __init__( + self, schema: SchemaPath, casters_factory: "SchemaCastersFactory" + ): super().__init__(schema) self.casters_factory = casters_factory diff --git a/openapi_core/casting/schemas/factories.py b/openapi_core/casting/schemas/factories.py index f99023dc..ea4638fa 100644 --- a/openapi_core/casting/schemas/factories.py +++ b/openapi_core/casting/schemas/factories.py @@ -1,11 +1,12 @@ from typing import Dict +from jsonschema_path import SchemaPath + from openapi_core.casting.schemas.casters import ArrayCaster from openapi_core.casting.schemas.casters import BaseSchemaCaster from openapi_core.casting.schemas.casters import CallableSchemaCaster from openapi_core.casting.schemas.casters import DummyCaster from openapi_core.casting.schemas.datatypes import CasterCallable -from openapi_core.spec import Spec from openapi_core.util import forcebool @@ -24,7 +25,7 @@ class SchemaCastersFactory: "array": ArrayCaster, } - def create(self, schema: Spec) -> BaseSchemaCaster: + def create(self, schema: SchemaPath) -> BaseSchemaCaster: schema_type = schema.getkey("type", "any") if schema_type in self.DUMMY_CASTERS: diff --git a/openapi_core/contrib/falcon/middlewares.py b/openapi_core/contrib/falcon/middlewares.py index 7a7d1533..4fc71661 100644 --- a/openapi_core/contrib/falcon/middlewares.py +++ b/openapi_core/contrib/falcon/middlewares.py @@ -5,6 +5,7 @@ from falcon.request import Request from falcon.response import Response +from jsonschema_path import SchemaPath from openapi_core.contrib.falcon.handlers import FalconOpenAPIErrorsHandler from openapi_core.contrib.falcon.handlers import ( @@ -12,7 +13,6 @@ ) from openapi_core.contrib.falcon.requests import FalconOpenAPIRequest from openapi_core.contrib.falcon.responses import FalconOpenAPIResponse -from openapi_core.spec import Spec from openapi_core.unmarshalling.processors import UnmarshallingProcessor from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType @@ -28,7 +28,7 @@ class FalconOpenAPIMiddleware(UnmarshallingProcessor[Request, Response]): def __init__( self, - spec: Spec, + spec: SchemaPath, request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None, response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None, request_cls: Type[FalconOpenAPIRequest] = FalconOpenAPIRequest, @@ -51,7 +51,7 @@ def __init__( @classmethod def from_spec( cls, - spec: Spec, + spec: SchemaPath, request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None, response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None, request_cls: Type[FalconOpenAPIRequest] = FalconOpenAPIRequest, diff --git a/openapi_core/contrib/flask/decorators.py b/openapi_core/contrib/flask/decorators.py index 3756f058..a379d136 100644 --- a/openapi_core/contrib/flask/decorators.py +++ b/openapi_core/contrib/flask/decorators.py @@ -8,13 +8,13 @@ from flask.globals import request from flask.wrappers import Request from flask.wrappers import Response +from jsonschema_path import SchemaPath from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler from openapi_core.contrib.flask.handlers import FlaskOpenAPIValidRequestHandler from openapi_core.contrib.flask.providers import FlaskRequestProvider from openapi_core.contrib.flask.requests import FlaskOpenAPIRequest from openapi_core.contrib.flask.responses import FlaskOpenAPIResponse -from openapi_core.spec import Spec from openapi_core.unmarshalling.processors import UnmarshallingProcessor from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType @@ -28,7 +28,7 @@ class FlaskOpenAPIViewDecorator(UnmarshallingProcessor[Request, Response]): def __init__( self, - spec: Spec, + spec: SchemaPath, request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None, response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None, request_cls: Type[FlaskOpenAPIRequest] = FlaskOpenAPIRequest, @@ -85,7 +85,7 @@ def _validate_response(self) -> bool: @classmethod def from_spec( cls, - spec: Spec, + spec: SchemaPath, request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None, response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None, request_cls: Type[FlaskOpenAPIRequest] = FlaskOpenAPIRequest, diff --git a/openapi_core/contrib/flask/views.py b/openapi_core/contrib/flask/views.py index 39bef43c..5fc233b4 100644 --- a/openapi_core/contrib/flask/views.py +++ b/openapi_core/contrib/flask/views.py @@ -2,10 +2,10 @@ from typing import Any from flask.views import MethodView +from jsonschema_path import SchemaPath from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler -from openapi_core.spec import Spec class FlaskOpenAPIView(MethodView): @@ -13,7 +13,7 @@ class FlaskOpenAPIView(MethodView): openapi_errors_handler = FlaskOpenAPIErrorsHandler - def __init__(self, spec: Spec, **unmarshaller_kwargs: Any): + def __init__(self, spec: SchemaPath, **unmarshaller_kwargs: Any): super().__init__() self.decorator = FlaskOpenAPIViewDecorator( diff --git a/openapi_core/deserializing/styles/deserializers.py b/openapi_core/deserializing/styles/deserializers.py index 16b92d1a..b29078a1 100644 --- a/openapi_core/deserializing/styles/deserializers.py +++ b/openapi_core/deserializing/styles/deserializers.py @@ -4,6 +4,8 @@ from typing import List from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.deserializing.exceptions import DeserializeError from openapi_core.deserializing.styles.datatypes import DeserializerCallable from openapi_core.deserializing.styles.exceptions import ( @@ -11,13 +13,12 @@ ) from openapi_core.schema.parameters import get_aslist from openapi_core.schema.parameters import get_explode -from openapi_core.spec import Spec class CallableStyleDeserializer: def __init__( self, - param_or_header: Spec, + param_or_header: SchemaPath, style: str, deserializer_callable: Optional[DeserializerCallable] = None, ): diff --git a/openapi_core/deserializing/styles/factories.py b/openapi_core/deserializing/styles/factories.py index a7a711e0..578316bf 100644 --- a/openapi_core/deserializing/styles/factories.py +++ b/openapi_core/deserializing/styles/factories.py @@ -2,13 +2,14 @@ from functools import partial from typing import Dict +from jsonschema_path import SchemaPath + from openapi_core.deserializing.styles.datatypes import DeserializerCallable from openapi_core.deserializing.styles.deserializers import ( CallableStyleDeserializer, ) from openapi_core.deserializing.styles.util import split from openapi_core.schema.parameters import get_style -from openapi_core.spec import Spec class StyleDeserializersFactory: @@ -20,7 +21,7 @@ class StyleDeserializersFactory: "deepObject": partial(re.split, pattern=r"\[|\]"), } - def create(self, param_or_header: Spec) -> CallableStyleDeserializer: + def create(self, param_or_header: SchemaPath) -> CallableStyleDeserializer: style = get_style(param_or_header) deserialize_callable = self.STYLE_DESERIALIZERS.get(style) diff --git a/openapi_core/extensions/models/factories.py b/openapi_core/extensions/models/factories.py index e10d59f9..0bf9a82f 100644 --- a/openapi_core/extensions/models/factories.py +++ b/openapi_core/extensions/models/factories.py @@ -8,15 +8,16 @@ from typing import Optional from typing import Type +from jsonschema_path import SchemaPath + from openapi_core.extensions.models.types import Field -from openapi_core.spec import Spec class DictFactory: base_class = dict def create( - self, schema: Spec, fields: Iterable[Field] + self, schema: SchemaPath, fields: Iterable[Field] ) -> Type[Dict[Any, Any]]: return self.base_class @@ -24,7 +25,7 @@ def create( class ModelFactory(DictFactory): def create( self, - schema: Spec, + schema: SchemaPath, fields: Iterable[Field], ) -> Type[Any]: name = schema.getkey("x-model") @@ -37,7 +38,7 @@ def create( class ModelPathFactory(ModelFactory): def create( self, - schema: Spec, + schema: SchemaPath, fields: Iterable[Field], ) -> Any: model_class_path = schema.getkey("x-model-path") diff --git a/openapi_core/finders.py b/openapi_core/finders.py index 9fbef8a1..3cb87b5c 100644 --- a/openapi_core/finders.py +++ b/openapi_core/finders.py @@ -3,8 +3,9 @@ from typing import Optional from typing import Type +from jsonschema_path import SchemaPath + from openapi_core.exceptions import SpecError -from openapi_core.spec import Spec from openapi_core.unmarshalling.request.types import RequestUnmarshallerType from openapi_core.unmarshalling.request.types import ( WebhookRequestUnmarshallerType, @@ -42,7 +43,7 @@ class SpecFinder: def __init__(self, specs: Mapping[SpecVersion, SpecClasses]) -> None: self.specs = specs - def get_classes(self, spec: Spec) -> SpecClasses: + def get_classes(self, spec: SchemaPath) -> SpecClasses: for v, classes in self.specs.items(): if v.name in spec and spec[v.name].startswith(v.version): return classes diff --git a/openapi_core/schema/parameters.py b/openapi_core/schema/parameters.py index e8ab1fdf..ec69cdf2 100644 --- a/openapi_core/schema/parameters.py +++ b/openapi_core/schema/parameters.py @@ -4,12 +4,13 @@ from typing import Mapping from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.schema.protocols import SuportsGetAll from openapi_core.schema.protocols import SuportsGetList -from openapi_core.spec import Spec -def get_aslist(param_or_header: Spec) -> bool: +def get_aslist(param_or_header: SchemaPath) -> bool: """Checks if parameter/header is described as list for simpler scenarios""" # if schema is not defined it's a complex scenario if "schema" not in param_or_header: @@ -21,7 +22,7 @@ def get_aslist(param_or_header: Spec) -> bool: return schema_type in ["array", "object"] -def get_style(param_or_header: Spec) -> str: +def get_style(param_or_header: SchemaPath) -> str: """Checks parameter/header style for simpler scenarios""" if "style" in param_or_header: assert isinstance(param_or_header["style"], str) @@ -34,7 +35,7 @@ def get_style(param_or_header: Spec) -> str: return "simple" if location in ["path", "header"] else "form" -def get_explode(param_or_header: Spec) -> bool: +def get_explode(param_or_header: SchemaPath) -> bool: """Checks parameter/header explode for simpler scenarios""" if "explode" in param_or_header: assert isinstance(param_or_header["explode"], bool) diff --git a/openapi_core/schema/schemas.py b/openapi_core/schema/schemas.py index 977e426b..7ddb6b17 100644 --- a/openapi_core/schema/schemas.py +++ b/openapi_core/schema/schemas.py @@ -1,10 +1,10 @@ from typing import Any from typing import Dict -from openapi_core.spec import Spec +from jsonschema_path import SchemaPath -def get_properties(schema: Spec) -> Dict[str, Any]: +def get_properties(schema: SchemaPath) -> Dict[str, Any]: properties = schema.get("properties", {}) properties_dict = dict(list(properties.items())) return properties_dict diff --git a/openapi_core/schema/servers.py b/openapi_core/schema/servers.py index e483f517..249c30bc 100644 --- a/openapi_core/schema/servers.py +++ b/openapi_core/schema/servers.py @@ -1,14 +1,14 @@ from typing import Any from typing import Dict -from openapi_core.spec import Spec +from jsonschema_path import SchemaPath def is_absolute(url: str) -> bool: return url.startswith("//") or "://" in url -def get_server_default_variables(server: Spec) -> Dict[str, Any]: +def get_server_default_variables(server: SchemaPath) -> Dict[str, Any]: if "variables" not in server: return {} @@ -19,7 +19,7 @@ def get_server_default_variables(server: Spec) -> Dict[str, Any]: return defaults -def get_server_url(server: Spec, **variables: Any) -> str: +def get_server_url(server: SchemaPath, **variables: Any) -> str: if not variables: variables = get_server_default_variables(server) assert isinstance(server["url"], str) diff --git a/openapi_core/schema/specs.py b/openapi_core/schema/specs.py index 5056a30d..0de09b08 100644 --- a/openapi_core/schema/specs.py +++ b/openapi_core/schema/specs.py @@ -1,7 +1,8 @@ +from jsonschema_path import SchemaPath + from openapi_core.schema.servers import get_server_url -from openapi_core.spec import Spec -def get_spec_url(spec: Spec, index: int = 0) -> str: +def get_spec_url(spec: SchemaPath, index: int = 0) -> str: servers = spec / "servers" return get_server_url(servers / 0) diff --git a/openapi_core/security/factories.py b/openapi_core/security/factories.py index 288edc69..3ab9b79b 100644 --- a/openapi_core/security/factories.py +++ b/openapi_core/security/factories.py @@ -2,11 +2,12 @@ from typing import Dict from typing import Type +from jsonschema_path import SchemaPath + from openapi_core.security.providers import ApiKeyProvider from openapi_core.security.providers import BaseProvider from openapi_core.security.providers import HttpProvider from openapi_core.security.providers import UnsupportedProvider -from openapi_core.spec import Spec class SecurityProviderFactory: @@ -17,7 +18,7 @@ class SecurityProviderFactory: "openIdConnect": UnsupportedProvider, } - def create(self, scheme: Spec) -> Any: + def create(self, scheme: SchemaPath) -> Any: scheme_type = scheme["type"] provider_class = self.PROVIDERS[scheme_type] return provider_class(scheme) diff --git a/openapi_core/security/providers.py b/openapi_core/security/providers.py index 3864682b..531feec3 100644 --- a/openapi_core/security/providers.py +++ b/openapi_core/security/providers.py @@ -1,13 +1,14 @@ import warnings from typing import Any +from jsonschema_path import SchemaPath + from openapi_core.datatypes import RequestParameters from openapi_core.security.exceptions import SecurityProviderError -from openapi_core.spec import Spec class BaseProvider: - def __init__(self, scheme: Spec): + def __init__(self, scheme: SchemaPath): self.scheme = scheme def __call__(self, parameters: RequestParameters) -> Any: diff --git a/openapi_core/shortcuts.py b/openapi_core/shortcuts.py index b4f8a6f5..42846d6e 100644 --- a/openapi_core/shortcuts.py +++ b/openapi_core/shortcuts.py @@ -4,6 +4,8 @@ from typing import Optional from typing import Union +from jsonschema_path import SchemaPath + from openapi_core.exceptions import SpecError from openapi_core.finders import SpecClasses from openapi_core.finders import SpecFinder @@ -85,21 +87,21 @@ } -def get_classes(spec: Spec) -> SpecClasses: +def get_classes(spec: SchemaPath) -> SpecClasses: return SpecFinder(SPECS).get_classes(spec) def unmarshal_apicall_request( request: Request, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[RequestUnmarshallerType] = None, **unmarshaller_kwargs: Any, ) -> RequestUnmarshalResult: if not isinstance(request, Request): raise TypeError("'request' argument is not type of Request") - if not isinstance(spec, Spec): - raise TypeError("'spec' argument is not type of Spec") + if not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.request_unmarshaller_cls @@ -113,15 +115,15 @@ def unmarshal_apicall_request( def unmarshal_webhook_request( request: WebhookRequest, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[WebhookRequestUnmarshallerType] = None, **unmarshaller_kwargs: Any, ) -> RequestUnmarshalResult: if not isinstance(request, WebhookRequest): raise TypeError("'request' argument is not type of WebhookRequest") - if not isinstance(spec, Spec): - raise TypeError("'spec' argument is not type of Spec") + if not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.webhook_request_unmarshaller_cls @@ -139,15 +141,15 @@ def unmarshal_webhook_request( def unmarshal_request( request: AnyRequest, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[AnyRequestUnmarshallerType] = None, **unmarshaller_kwargs: Any, ) -> RequestUnmarshalResult: 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if isinstance(request, WebhookRequest): if cls is None or issubclass(cls, WebhookRequestUnmarshaller): return unmarshal_webhook_request( @@ -179,7 +181,7 @@ def unmarshal_request( def unmarshal_apicall_response( request: Request, response: Response, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[ResponseUnmarshallerType] = None, **unmarshaller_kwargs: Any, @@ -188,8 +190,8 @@ def unmarshal_apicall_response( raise TypeError("'request' argument is not type of 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.response_unmarshaller_cls @@ -204,7 +206,7 @@ def unmarshal_apicall_response( def unmarshal_webhook_response( request: WebhookRequest, response: Response, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[WebhookResponseUnmarshallerType] = None, **unmarshaller_kwargs: Any, @@ -213,8 +215,8 @@ def unmarshal_webhook_response( raise TypeError("'request' argument is not type of WebhookRequest") 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.webhook_response_unmarshaller_cls @@ -233,7 +235,7 @@ def unmarshal_webhook_response( def unmarshal_response( request: AnyRequest, response: Response, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[AnyResponseUnmarshallerType] = None, **unmarshaller_kwargs: Any, @@ -242,8 +244,8 @@ def unmarshal_response( 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if isinstance(request, WebhookRequest): if cls is None or issubclass(cls, WebhookResponseUnmarshaller): return unmarshal_webhook_response( @@ -276,15 +278,15 @@ def unmarshal_response( def validate_request( request: AnyRequest, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[AnyRequestValidatorType] = None, **validator_kwargs: Any, ) -> Optional[RequestUnmarshalResult]: 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if isinstance(request, WebhookRequest): if cls is None or issubclass(cls, WebhookRequestValidator): @@ -317,7 +319,7 @@ def validate_request( def validate_response( request: Union[Request, WebhookRequest, Spec], response: Union[Response, Request, WebhookRequest], - spec: Union[Spec, Response], + spec: Union[SchemaPath, Response], base_url: Optional[str] = None, cls: Optional[AnyResponseValidatorType] = None, **validator_kwargs: Any, @@ -326,8 +328,8 @@ def validate_response( 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if isinstance(request, WebhookRequest): if cls is None or issubclass(cls, WebhookResponseValidator): @@ -361,15 +363,15 @@ def validate_response( def validate_apicall_request( request: Request, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[RequestValidatorType] = None, **validator_kwargs: Any, ) -> None: if not isinstance(request, Request): raise TypeError("'request' argument is not type of Request") - if not isinstance(spec, Spec): - raise TypeError("'spec' argument is not type of Spec") + if not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.request_validator_cls @@ -381,15 +383,15 @@ def validate_apicall_request( def validate_webhook_request( request: WebhookRequest, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[WebhookRequestValidatorType] = None, **validator_kwargs: Any, ) -> None: if not isinstance(request, WebhookRequest): raise TypeError("'request' argument is not type of WebhookRequest") - if not isinstance(spec, Spec): - raise TypeError("'spec' argument is not type of Spec") + if not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.webhook_request_validator_cls @@ -406,7 +408,7 @@ def validate_webhook_request( def validate_apicall_response( request: Request, response: Response, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[ResponseValidatorType] = None, **validator_kwargs: Any, @@ -415,8 +417,8 @@ def validate_apicall_response( raise TypeError("'request' argument is not type of 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.response_validator_cls @@ -429,7 +431,7 @@ def validate_apicall_response( def validate_webhook_response( request: WebhookRequest, response: Response, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, cls: Optional[WebhookResponseValidatorType] = None, **validator_kwargs: Any, @@ -438,8 +440,8 @@ def validate_webhook_response( raise TypeError("'request' argument is not type of WebhookRequest") 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 not isinstance(spec, SchemaPath): + raise TypeError("'spec' argument is not type of SchemaPath") if cls is None: classes = get_classes(spec) cls = classes.webhook_response_validator_cls diff --git a/openapi_core/spec/paths.py b/openapi_core/spec/paths.py index db0aee44..f045cac8 100644 --- a/openapi_core/spec/paths.py +++ b/openapi_core/spec/paths.py @@ -1,10 +1,11 @@ +import warnings from typing import Any from typing import Hashable from typing import Mapping from typing import Type from typing import TypeVar -from jsonschema_spec import SchemaPath +from jsonschema_path import SchemaPath from openapi_spec_validator.validation import openapi_spec_validator_proxy TSpec = TypeVar("TSpec", bound="Spec") @@ -20,6 +21,10 @@ def from_dict( *args: Any, **kwargs: Any, ) -> TSpec: + warnings.warn( + "Spec is deprecated. Use SchemaPath from jsonschema-path package.", + DeprecationWarning, + ) validator = kwargs.pop("validator", openapi_spec_validator_proxy) if validator is not None: base_uri = kwargs.get("base_uri", "") @@ -27,14 +32,3 @@ def from_dict( validator.validate(data, base_uri=base_uri, spec_url=spec_url) return super().from_dict(data, *args, **kwargs) - - def exists(self) -> bool: - try: - self.content() - except KeyError: - return False - else: - return True - - def uri(self) -> str: - return f"#/{str(self)}" diff --git a/openapi_core/templating/media_types/finders.py b/openapi_core/templating/media_types/finders.py index 15ffe89e..ee7ae989 100644 --- a/openapi_core/templating/media_types/finders.py +++ b/openapi_core/templating/media_types/finders.py @@ -3,13 +3,14 @@ from typing import Mapping from typing import Tuple -from openapi_core.spec import Spec +from jsonschema_path import SchemaPath + from openapi_core.templating.media_types.datatypes import MediaType from openapi_core.templating.media_types.exceptions import MediaTypeNotFound class MediaTypeFinder: - def __init__(self, content: Spec): + def __init__(self, content: SchemaPath): self.content = content def get_first(self) -> MediaType: diff --git a/openapi_core/templating/paths/finders.py b/openapi_core/templating/paths/finders.py index e6f70841..10e7f027 100644 --- a/openapi_core/templating/paths/finders.py +++ b/openapi_core/templating/paths/finders.py @@ -5,10 +5,10 @@ from urllib.parse import urljoin from urllib.parse import urlparse +from jsonschema_path import SchemaPath from more_itertools import peekable from openapi_core.schema.servers import is_absolute -from openapi_core.spec import Spec from openapi_core.templating.datatypes import TemplateResult from openapi_core.templating.paths.datatypes import Path from openapi_core.templating.paths.datatypes import PathOperation @@ -23,7 +23,7 @@ class BasePathFinder: - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): self.spec = spec self.base_url = base_url @@ -69,14 +69,14 @@ def _get_servers_iter( class APICallPathFinder(BasePathFinder): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): self.spec = spec self.base_url = base_url def _get_paths_iter(self, name: str) -> Iterator[Path]: paths = self.spec / "paths" if not paths.exists(): - raise PathsNotFound(paths.uri()) + raise PathsNotFound(paths.as_uri()) template_paths: List[Path] = [] for path_pattern, path in list(paths.items()): # simple path. @@ -145,7 +145,7 @@ class WebhookPathFinder(BasePathFinder): def _get_paths_iter(self, name: str) -> Iterator[Path]: webhooks = self.spec / "webhooks" if not webhooks.exists(): - raise PathsNotFound(webhooks.uri()) + raise PathsNotFound(webhooks.as_uri()) for webhook_name, path in list(webhooks.items()): if name == webhook_name: path_result = TemplateResult(webhook_name, {}) diff --git a/openapi_core/templating/paths/util.py b/openapi_core/templating/paths/util.py index a89c6d3b..b6844555 100644 --- a/openapi_core/templating/paths/util.py +++ b/openapi_core/templating/paths/util.py @@ -1,6 +1,5 @@ from typing import Tuple -from openapi_core.spec.paths import Spec from openapi_core.templating.paths.datatypes import Path diff --git a/openapi_core/templating/responses/finders.py b/openapi_core/templating/responses/finders.py index c78f170a..b05cda91 100644 --- a/openapi_core/templating/responses/finders.py +++ b/openapi_core/templating/responses/finders.py @@ -1,12 +1,13 @@ -from openapi_core.spec import Spec +from jsonschema_path import SchemaPath + from openapi_core.templating.responses.exceptions import ResponseNotFound class ResponseFinder: - def __init__(self, responses: Spec): + def __init__(self, responses: SchemaPath): self.responses = responses - def find(self, http_status: str = "default") -> Spec: + def find(self, http_status: str = "default") -> SchemaPath: if http_status in self.responses: return self.responses / http_status diff --git a/openapi_core/unmarshalling/processors.py b/openapi_core/unmarshalling/processors.py index fcec7c26..f6afed1b 100644 --- a/openapi_core/unmarshalling/processors.py +++ b/openapi_core/unmarshalling/processors.py @@ -3,10 +3,11 @@ from typing import Generic from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.shortcuts import get_classes -from openapi_core.spec import Spec from openapi_core.typing import ErrorsHandlerCallable from openapi_core.typing import RequestType from openapi_core.typing import ResponseType @@ -24,7 +25,7 @@ class UnmarshallingProcessor(Generic[RequestType, ResponseType]): def __init__( self, - spec: Spec, + spec: SchemaPath, request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None, response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None, **unmarshaller_kwargs: Any, diff --git a/openapi_core/unmarshalling/request/processors.py b/openapi_core/unmarshalling/request/processors.py index 1719605e..a2e04e13 100644 --- a/openapi_core/unmarshalling/request/processors.py +++ b/openapi_core/unmarshalling/request/processors.py @@ -1,8 +1,9 @@ from typing import Any from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request -from openapi_core.spec import Spec from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult from openapi_core.unmarshalling.request.protocols import RequestUnmarshaller from openapi_core.unmarshalling.request.types import RequestUnmarshallerType @@ -11,7 +12,7 @@ class RequestUnmarshallingProcessor: def __init__( self, - spec: Spec, + spec: SchemaPath, request_unmarshaller_cls: RequestUnmarshallerType, **unmarshaller_kwargs: Any ) -> None: diff --git a/openapi_core/unmarshalling/request/protocols.py b/openapi_core/unmarshalling/request/protocols.py index cb346828..388f13c8 100644 --- a/openapi_core/unmarshalling/request/protocols.py +++ b/openapi_core/unmarshalling/request/protocols.py @@ -3,15 +3,16 @@ from typing import Protocol from typing import runtime_checkable +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import WebhookRequest -from openapi_core.spec import Spec from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult @runtime_checkable class RequestUnmarshaller(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def unmarshal( @@ -23,7 +24,7 @@ def unmarshal( @runtime_checkable class WebhookRequestUnmarshaller(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def unmarshal( diff --git a/openapi_core/unmarshalling/request/unmarshallers.py b/openapi_core/unmarshalling/request/unmarshallers.py index 3a201176..a003c9db 100644 --- a/openapi_core/unmarshalling/request/unmarshallers.py +++ b/openapi_core/unmarshalling/request/unmarshallers.py @@ -1,5 +1,7 @@ from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.casting.schemas import schema_casters_factory from openapi_core.casting.schemas.factories import SchemaCastersFactory from openapi_core.deserializing.media_types import ( @@ -20,7 +22,6 @@ from openapi_core.protocols import WebhookRequest from openapi_core.security import security_provider_factory from openapi_core.security.factories import SecurityProviderFactory -from openapi_core.spec import Spec from openapi_core.templating.paths.exceptions import PathError from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult from openapi_core.unmarshalling.schemas import ( @@ -81,7 +82,7 @@ class BaseRequestUnmarshaller(BaseRequestValidator, BaseUnmarshaller): def __init__( self, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, schema_casters_factory: SchemaCastersFactory = schema_casters_factory, style_deserializers_factory: StyleDeserializersFactory = style_deserializers_factory, @@ -129,7 +130,7 @@ def __init__( ) def _unmarshal( - self, request: BaseRequest, operation: Spec, path: Spec + self, request: BaseRequest, operation: SchemaPath, path: SchemaPath ) -> RequestUnmarshalResult: try: security = self._get_security(request.parameters, operation) @@ -164,7 +165,7 @@ def _unmarshal( ) def _unmarshal_body( - self, request: BaseRequest, operation: Spec, path: Spec + self, request: BaseRequest, operation: SchemaPath, path: SchemaPath ) -> RequestUnmarshalResult: try: body = self._get_body(request.body, request.mimetype, operation) @@ -183,7 +184,7 @@ def _unmarshal_body( ) def _unmarshal_parameters( - self, request: BaseRequest, operation: Spec, path: Spec + self, request: BaseRequest, operation: SchemaPath, path: SchemaPath ) -> RequestUnmarshalResult: try: params = self._get_parameters(request.parameters, path, operation) @@ -199,7 +200,7 @@ def _unmarshal_parameters( ) def _unmarshal_security( - self, request: BaseRequest, operation: Spec, path: Spec + self, request: BaseRequest, operation: SchemaPath, path: SchemaPath ) -> RequestUnmarshalResult: try: security = self._get_security(request.parameters, operation) diff --git a/openapi_core/unmarshalling/response/processors.py b/openapi_core/unmarshalling/response/processors.py index 517af232..cb0d219e 100644 --- a/openapi_core/unmarshalling/response/processors.py +++ b/openapi_core/unmarshalling/response/processors.py @@ -1,9 +1,10 @@ from typing import Any from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import Response -from openapi_core.spec import Spec from openapi_core.unmarshalling.response.datatypes import ( ResponseUnmarshalResult, ) @@ -14,7 +15,7 @@ class ResponseUnmarshallingProcessor: def __init__( self, - spec: Spec, + spec: SchemaPath, response_unmarshaller_cls: ResponseUnmarshallerType, **unmarshaller_kwargs: Any ) -> None: diff --git a/openapi_core/unmarshalling/response/protocols.py b/openapi_core/unmarshalling/response/protocols.py index 1262da19..8666e84d 100644 --- a/openapi_core/unmarshalling/response/protocols.py +++ b/openapi_core/unmarshalling/response/protocols.py @@ -5,10 +5,11 @@ from typing import Protocol from typing import runtime_checkable +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.protocols import WebhookRequest -from openapi_core.spec import Spec from openapi_core.unmarshalling.response.datatypes import ( ResponseUnmarshalResult, ) @@ -16,7 +17,7 @@ @runtime_checkable class ResponseUnmarshaller(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def unmarshal( @@ -29,7 +30,7 @@ def unmarshal( @runtime_checkable class WebhookResponseUnmarshaller(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def unmarshal( diff --git a/openapi_core/unmarshalling/response/unmarshallers.py b/openapi_core/unmarshalling/response/unmarshallers.py index ce88a753..78a816de 100644 --- a/openapi_core/unmarshalling/response/unmarshallers.py +++ b/openapi_core/unmarshalling/response/unmarshallers.py @@ -1,7 +1,8 @@ +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.protocols import WebhookRequest -from openapi_core.spec import Spec from openapi_core.templating.paths.exceptions import PathError from openapi_core.templating.responses.exceptions import ResponseFinderError from openapi_core.unmarshalling.response.datatypes import ( @@ -53,7 +54,7 @@ class BaseResponseUnmarshaller(BaseResponseValidator, BaseUnmarshaller): def _unmarshal( self, response: Response, - operation: Spec, + operation: SchemaPath, ) -> ResponseUnmarshalResult: try: operation_response = self._find_operation_response( @@ -93,7 +94,7 @@ def _unmarshal( def _unmarshal_data( self, response: Response, - operation: Spec, + operation: SchemaPath, ) -> ResponseUnmarshalResult: try: operation_response = self._find_operation_response( @@ -121,7 +122,7 @@ def _unmarshal_data( def _unmarshal_headers( self, response: Response, - operation: Spec, + operation: SchemaPath, ) -> ResponseUnmarshalResult: try: operation_response = self._find_operation_response( diff --git a/openapi_core/unmarshalling/schemas/factories.py b/openapi_core/unmarshalling/schemas/factories.py index 01bf73e2..948113a1 100644 --- a/openapi_core/unmarshalling/schemas/factories.py +++ b/openapi_core/unmarshalling/schemas/factories.py @@ -2,7 +2,8 @@ import warnings from typing import Optional -from openapi_core.spec import Spec +from jsonschema_path import SchemaPath + from openapi_core.unmarshalling.schemas.datatypes import ( FormatUnmarshallersDict, ) @@ -33,7 +34,7 @@ def __init__( def create( self, - schema: Spec, + schema: SchemaPath, format_validators: Optional[FormatValidatorsDict] = None, format_unmarshallers: Optional[FormatUnmarshallersDict] = None, extra_format_validators: Optional[FormatValidatorsDict] = None, diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 98dffce3..9c574b84 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -8,9 +8,10 @@ from typing import Type from typing import Union +from jsonschema_path import SchemaPath + from openapi_core.extensions.models.factories import ModelPathFactory from openapi_core.schema.schemas import get_properties -from openapi_core.spec import Spec from openapi_core.unmarshalling.schemas.datatypes import FormatUnmarshaller from openapi_core.unmarshalling.schemas.datatypes import ( FormatUnmarshallersDict, @@ -25,7 +26,7 @@ class PrimitiveUnmarshaller: def __init__( self, - schema: Spec, + schema: SchemaPath, schema_validator: SchemaValidator, schema_unmarshaller: "SchemaUnmarshaller", ) -> None: @@ -44,9 +45,7 @@ def __call__(self, value: Any) -> Optional[List[Any]]: @property def items_unmarshaller(self) -> "SchemaUnmarshaller": # sometimes we don't have any schema i.e. free-form objects - items_schema = self.schema.get( - "items", Spec.from_dict({}, validator=None) - ) + items_schema = self.schema.get("items", SchemaPath.from_dict({})) return self.schema_unmarshaller.evolve(items_schema) @@ -63,7 +62,7 @@ def __call__(self, value: Any) -> Any: def object_class_factory(self) -> ModelPathFactory: return ModelPathFactory() - def evolve(self, schema: Spec) -> "ObjectUnmarshaller": + def evolve(self, schema: SchemaPath) -> "ObjectUnmarshaller": cls = self.__class__ return cls( @@ -119,8 +118,8 @@ def _unmarshal_properties( if additional_properties is not False: # free-form object if additional_properties is True: - additional_prop_schema = Spec.from_dict( - {"nullable": True}, validator=None + additional_prop_schema = SchemaPath.from_dict( + {"nullable": True} ) # defined schema else: @@ -249,7 +248,7 @@ def __contains__(self, schema_format: str) -> bool: class SchemaUnmarshaller: def __init__( self, - schema: Spec, + schema: SchemaPath, schema_validator: SchemaValidator, types_unmarshaller: TypesUnmarshaller, formats_unmarshaller: FormatsUnmarshaller, @@ -294,7 +293,7 @@ def get_type_unmarshaller( self, ) - def evolve(self, schema: Spec) -> "SchemaUnmarshaller": + def evolve(self, schema: SchemaPath) -> "SchemaUnmarshaller": cls = self.__class__ return cls( diff --git a/openapi_core/unmarshalling/unmarshallers.py b/openapi_core/unmarshalling/unmarshallers.py index be41d60e..b0a4192b 100644 --- a/openapi_core/unmarshalling/unmarshallers.py +++ b/openapi_core/unmarshalling/unmarshallers.py @@ -3,6 +3,8 @@ from typing import Optional from typing import Tuple +from jsonschema_path import SchemaPath + from openapi_core.casting.schemas import schema_casters_factory from openapi_core.casting.schemas.factories import SchemaCastersFactory from openapi_core.deserializing.media_types import ( @@ -18,7 +20,6 @@ from openapi_core.deserializing.styles.factories import ( StyleDeserializersFactory, ) -from openapi_core.spec import Spec from openapi_core.unmarshalling.schemas.datatypes import ( FormatUnmarshallersDict, ) @@ -35,7 +36,7 @@ class BaseUnmarshaller(BaseValidator): def __init__( self, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, schema_casters_factory: SchemaCastersFactory = schema_casters_factory, style_deserializers_factory: StyleDeserializersFactory = style_deserializers_factory, @@ -77,7 +78,7 @@ def __init__( self.format_unmarshallers = format_unmarshallers self.extra_format_unmarshallers = extra_format_unmarshallers - def _unmarshal_schema(self, schema: Spec, value: Any) -> Any: + def _unmarshal_schema(self, schema: SchemaPath, value: Any) -> Any: unmarshaller = self.schema_unmarshallers_factory.create( schema, format_validators=self.format_validators, @@ -90,7 +91,7 @@ def _unmarshal_schema(self, schema: Spec, value: Any) -> Any: def _convert_schema_style_value( self, raw: Any, - param_or_header: Spec, + param_or_header: SchemaPath, ) -> Any: casted, schema = self._convert_schema_style_value_and_schema( raw, param_or_header @@ -100,7 +101,7 @@ def _convert_schema_style_value( return self._unmarshal_schema(schema, casted) def _convert_content_schema_value( - self, raw: Any, content: Spec, mimetype: Optional[str] = None + self, raw: Any, content: SchemaPath, mimetype: Optional[str] = None ) -> Any: casted, schema = self._convert_content_schema_value_and_schema( raw, content, mimetype diff --git a/openapi_core/validation/processors.py b/openapi_core/validation/processors.py index cef967af..711b5225 100644 --- a/openapi_core/validation/processors.py +++ b/openapi_core/validation/processors.py @@ -2,10 +2,11 @@ from typing import Any from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.shortcuts import get_classes -from openapi_core.spec import Spec from openapi_core.validation.request.types import RequestValidatorType from openapi_core.validation.response.types import ResponseValidatorType @@ -13,7 +14,7 @@ class ValidationProcessor: def __init__( self, - spec: Spec, + spec: SchemaPath, request_validator_cls: Optional[RequestValidatorType] = None, response_validator_cls: Optional[ResponseValidatorType] = None, **unmarshaller_kwargs: Any, diff --git a/openapi_core/validation/request/exceptions.py b/openapi_core/validation/request/exceptions.py index 6d5d3f66..eb27a5c3 100644 --- a/openapi_core/validation/request/exceptions.py +++ b/openapi_core/validation/request/exceptions.py @@ -1,9 +1,10 @@ from dataclasses import dataclass from typing import Iterable +from jsonschema_path import SchemaPath + from openapi_core.datatypes import Parameters from openapi_core.exceptions import OpenAPIError -from openapi_core.spec import Spec from openapi_core.validation.exceptions import ValidationError from openapi_core.validation.schemas.exceptions import ValidateError @@ -47,7 +48,7 @@ class ParameterValidationError(RequestValidationError): location: str @classmethod - def from_spec(cls, spec: Spec) -> "ParameterValidationError": + def from_spec(cls, spec: SchemaPath) -> "ParameterValidationError": return cls(spec["name"], spec["in"]) def __str__(self) -> str: diff --git a/openapi_core/validation/request/protocols.py b/openapi_core/validation/request/protocols.py index c18060db..e27f5863 100644 --- a/openapi_core/validation/request/protocols.py +++ b/openapi_core/validation/request/protocols.py @@ -4,14 +4,15 @@ from typing import Protocol from typing import runtime_checkable +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import WebhookRequest -from openapi_core.spec import Spec @runtime_checkable class RequestValidator(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def iter_errors( @@ -29,7 +30,7 @@ def validate( @runtime_checkable class WebhookRequestValidator(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def iter_errors( diff --git a/openapi_core/validation/request/validators.py b/openapi_core/validation/request/validators.py index 3c2ed782..b1e7ffe0 100644 --- a/openapi_core/validation/request/validators.py +++ b/openapi_core/validation/request/validators.py @@ -5,6 +5,8 @@ from typing import Iterator from typing import Optional +from jsonschema_path import SchemaPath + from openapi_core.casting.schemas import schema_casters_factory from openapi_core.casting.schemas.factories import SchemaCastersFactory from openapi_core.datatypes import Parameters @@ -28,7 +30,6 @@ from openapi_core.security import security_provider_factory from openapi_core.security.exceptions import SecurityProviderError from openapi_core.security.factories import SecurityProviderFactory -from openapi_core.spec.paths import Spec from openapi_core.templating.paths.exceptions import PathError from openapi_core.templating.paths.finders import WebhookPathFinder from openapi_core.templating.security.exceptions import SecurityNotFound @@ -63,7 +64,7 @@ class BaseRequestValidator(BaseValidator): def __init__( self, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, schema_casters_factory: SchemaCastersFactory = schema_casters_factory, style_deserializers_factory: StyleDeserializersFactory = style_deserializers_factory, @@ -90,7 +91,7 @@ def __init__( self.security_provider_factory = security_provider_factory def _iter_errors( - self, request: BaseRequest, operation: Spec, path: Spec + self, request: BaseRequest, operation: SchemaPath, path: SchemaPath ) -> Iterator[Exception]: try: self._get_security(request.parameters, operation) @@ -110,7 +111,7 @@ def _iter_errors( yield exc def _iter_body_errors( - self, request: BaseRequest, operation: Spec + self, request: BaseRequest, operation: SchemaPath ) -> Iterator[Exception]: try: self._get_body(request.body, request.mimetype, operation) @@ -118,7 +119,7 @@ def _iter_body_errors( yield exc def _iter_parameters_errors( - self, request: BaseRequest, operation: Spec, path: Spec + self, request: BaseRequest, operation: SchemaPath, path: SchemaPath ) -> Iterator[Exception]: try: self._get_parameters(request.parameters, path, operation) @@ -126,7 +127,7 @@ def _iter_parameters_errors( yield from exc.errors def _iter_security_errors( - self, request: BaseRequest, operation: Spec + self, request: BaseRequest, operation: SchemaPath ) -> Iterator[Exception]: try: self._get_security(request.parameters, operation) @@ -136,8 +137,8 @@ def _iter_security_errors( def _get_parameters( self, parameters: RequestParameters, - operation: Spec, - path: Spec, + operation: SchemaPath, + path: SchemaPath, ) -> Parameters: operation_params = operation.get("parameters", []) path_params = path.get("parameters", []) @@ -177,7 +178,7 @@ def _get_parameters( spec="param", ) def _get_parameter( - self, parameters: RequestParameters, param: Spec + self, parameters: RequestParameters, param: SchemaPath ) -> Any: name = param["name"] deprecated = param.getkey("deprecated", False) @@ -200,7 +201,7 @@ def _get_parameter( @ValidationErrorWrapper(SecurityValidationError, InvalidSecurity) def _get_security( - self, parameters: RequestParameters, operation: Spec + self, parameters: RequestParameters, operation: SchemaPath ) -> Optional[Dict[str, str]]: security = None if "security" in self.spec: @@ -239,7 +240,7 @@ def _get_security_value( @ValidationErrorWrapper(RequestBodyValidationError, InvalidRequestBody) def _get_body( - self, body: Optional[str], mimetype: str, operation: Spec + self, body: Optional[str], mimetype: str, operation: SchemaPath ) -> Any: if "requestBody" not in operation: return None @@ -251,7 +252,9 @@ def _get_body( raw_body = self._get_body_value(body, request_body) return self._convert_content_schema_value(raw_body, content, mimetype) - def _get_body_value(self, body: Optional[str], request_body: Spec) -> Any: + def _get_body_value( + self, body: Optional[str], request_body: SchemaPath + ) -> Any: if not body: if request_body.getkey("required", False): raise MissingRequiredRequestBody diff --git a/openapi_core/validation/response/protocols.py b/openapi_core/validation/response/protocols.py index a5f646bb..7a403d3e 100644 --- a/openapi_core/validation/response/protocols.py +++ b/openapi_core/validation/response/protocols.py @@ -4,15 +4,16 @@ from typing import Protocol from typing import runtime_checkable +from jsonschema_path import SchemaPath + from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.protocols import WebhookRequest -from openapi_core.spec import Spec @runtime_checkable class ResponseValidator(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def iter_errors( @@ -32,7 +33,7 @@ def validate( @runtime_checkable class WebhookResponseValidator(Protocol): - def __init__(self, spec: Spec, base_url: Optional[str] = None): + def __init__(self, spec: SchemaPath, base_url: Optional[str] = None): ... def iter_errors( diff --git a/openapi_core/validation/response/validators.py b/openapi_core/validation/response/validators.py index 1bb494eb..5f2ce662 100644 --- a/openapi_core/validation/response/validators.py +++ b/openapi_core/validation/response/validators.py @@ -6,11 +6,12 @@ from typing import List from typing import Mapping +from jsonschema_path import SchemaPath + from openapi_core.exceptions import OpenAPIError from openapi_core.protocols import Request from openapi_core.protocols import Response from openapi_core.protocols import WebhookRequest -from openapi_core.spec import Spec from openapi_core.templating.paths.exceptions import PathError from openapi_core.templating.responses.exceptions import ResponseFinderError from openapi_core.validation.decorators import ValidationErrorWrapper @@ -39,7 +40,7 @@ def _iter_errors( data: str, headers: Mapping[str, Any], mimetype: str, - operation: Spec, + operation: SchemaPath, ) -> Iterator[Exception]: try: operation_response = self._find_operation_response( @@ -61,7 +62,7 @@ def _iter_errors( yield from exc.context def _iter_data_errors( - self, status_code: int, data: str, mimetype: str, operation: Spec + self, status_code: int, data: str, mimetype: str, operation: SchemaPath ) -> Iterator[Exception]: try: operation_response = self._find_operation_response( @@ -78,7 +79,10 @@ def _iter_data_errors( yield exc def _iter_headers_errors( - self, status_code: int, headers: Mapping[str, Any], operation: Spec + self, + status_code: int, + headers: Mapping[str, Any], + operation: SchemaPath, ) -> Iterator[Exception]: try: operation_response = self._find_operation_response( @@ -97,8 +101,8 @@ def _iter_headers_errors( def _find_operation_response( self, status_code: int, - operation: Spec, - ) -> Spec: + operation: SchemaPath, + ) -> SchemaPath: from openapi_core.templating.responses.finders import ResponseFinder finder = ResponseFinder(operation / "responses") @@ -106,7 +110,7 @@ def _find_operation_response( @ValidationErrorWrapper(DataValidationError, InvalidData) def _get_data( - self, data: str, mimetype: str, operation_response: Spec + self, data: str, mimetype: str, operation_response: SchemaPath ) -> Any: if "content" not in operation_response: return None @@ -123,7 +127,7 @@ def _get_data_value(self, data: str) -> Any: return data def _get_headers( - self, headers: Mapping[str, Any], operation_response: Spec + self, headers: Mapping[str, Any], operation_response: SchemaPath ) -> Dict[str, Any]: if "headers" not in operation_response: return {} @@ -153,7 +157,7 @@ def _get_headers( @ValidationErrorWrapper(HeaderValidationError, InvalidHeader, name="name") def _get_header( - self, headers: Mapping[str, Any], name: str, header: Spec + self, headers: Mapping[str, Any], name: str, header: SchemaPath ) -> Any: deprecated = header.getkey("deprecated", False) if deprecated: diff --git a/openapi_core/validation/schemas/factories.py b/openapi_core/validation/schemas/factories.py index fe7f4df5..e4b316c0 100644 --- a/openapi_core/validation/schemas/factories.py +++ b/openapi_core/validation/schemas/factories.py @@ -5,8 +5,8 @@ from jsonschema._format import FormatChecker from jsonschema.protocols import Validator +from jsonschema_path import SchemaPath -from openapi_core.spec import Spec from openapi_core.validation.schemas.datatypes import FormatValidatorsDict from openapi_core.validation.schemas.validators import SchemaValidator @@ -51,7 +51,7 @@ def _add_validators( def create( self, - schema: Spec, + schema: SchemaPath, format_validators: Optional[FormatValidatorsDict] = None, extra_format_validators: Optional[FormatValidatorsDict] = None, ) -> Validator: diff --git a/openapi_core/validation/schemas/validators.py b/openapi_core/validation/schemas/validators.py index 2193d029..6a4954e9 100644 --- a/openapi_core/validation/schemas/validators.py +++ b/openapi_core/validation/schemas/validators.py @@ -7,8 +7,8 @@ from jsonschema.exceptions import FormatError from jsonschema.protocols import Validator +from jsonschema_path import SchemaPath -from openapi_core.spec import Spec from openapi_core.validation.schemas.datatypes import FormatValidator from openapi_core.validation.schemas.exceptions import InvalidSchemaValue from openapi_core.validation.schemas.exceptions import ValidateError @@ -19,7 +19,7 @@ class SchemaValidator: def __init__( self, - schema: Spec, + schema: SchemaPath, validator: Validator, ): self.schema = schema @@ -35,7 +35,7 @@ def validate(self, value: Any) -> None: schema_type = self.schema.getkey("type", "any") raise InvalidSchemaValue(value, schema_type, schema_errors=errors) - def evolve(self, schema: Spec) -> "SchemaValidator": + def evolve(self, schema: SchemaPath) -> "SchemaValidator": cls = self.__class__ with schema.open() as schema_dict: @@ -78,7 +78,7 @@ def format_validator_callable(self) -> FormatValidator: return lambda x: True - def iter_valid_schemas(self, value: Any) -> Iterator[Spec]: + def iter_valid_schemas(self, value: Any) -> Iterator[SchemaPath]: yield self.schema one_of_schema = self.get_one_of_schema(value) @@ -91,7 +91,7 @@ def iter_valid_schemas(self, value: Any) -> Iterator[Spec]: def get_one_of_schema( self, value: Any, - ) -> Optional[Spec]: + ) -> Optional[SchemaPath]: if "oneOf" not in self.schema: return None @@ -111,7 +111,7 @@ def get_one_of_schema( def iter_any_of_schemas( self, value: Any, - ) -> Iterator[Spec]: + ) -> Iterator[SchemaPath]: if "anyOf" not in self.schema: return @@ -128,7 +128,7 @@ def iter_any_of_schemas( def iter_all_of_schemas( self, value: Any, - ) -> Iterator[Spec]: + ) -> Iterator[SchemaPath]: if "allOf" not in self.schema: return diff --git a/openapi_core/validation/validators.py b/openapi_core/validation/validators.py index b9e7f397..4a864816 100644 --- a/openapi_core/validation/validators.py +++ b/openapi_core/validation/validators.py @@ -7,6 +7,8 @@ from typing import Tuple from urllib.parse import urljoin +from jsonschema_path import SchemaPath + from openapi_core.casting.schemas import schema_casters_factory from openapi_core.casting.schemas.factories import SchemaCastersFactory from openapi_core.deserializing.media_types import ( @@ -30,7 +32,6 @@ from openapi_core.schema.parameters import get_style from openapi_core.schema.protocols import SuportsGetAll from openapi_core.schema.protocols import SuportsGetList -from openapi_core.spec import Spec from openapi_core.templating.media_types.datatypes import MediaType from openapi_core.templating.paths.datatypes import PathOperationServer from openapi_core.templating.paths.finders import APICallPathFinder @@ -45,7 +46,7 @@ class BaseValidator: def __init__( self, - spec: Spec, + spec: SchemaPath, base_url: Optional[str] = None, schema_casters_factory: SchemaCastersFactory = schema_casters_factory, style_deserializers_factory: StyleDeserializersFactory = style_deserializers_factory, @@ -77,7 +78,7 @@ def __init__( self.extra_media_type_deserializers = extra_media_type_deserializers def _find_media_type( - self, content: Spec, mimetype: Optional[str] = None + self, content: SchemaPath, mimetype: Optional[str] = None ) -> MediaType: from openapi_core.templating.media_types.finders import MediaTypeFinder @@ -96,15 +97,17 @@ def _deserialise_media_type( ) return deserializer.deserialize(value) - def _deserialise_style(self, param_or_header: Spec, value: Any) -> Any: + def _deserialise_style( + self, param_or_header: SchemaPath, value: Any + ) -> Any: deserializer = self.style_deserializers_factory.create(param_or_header) return deserializer.deserialize(value) - def _cast(self, schema: Spec, value: Any) -> Any: + def _cast(self, schema: SchemaPath, value: Any) -> Any: caster = self.schema_casters_factory.create(schema) return caster(value) - def _validate_schema(self, schema: Spec, value: Any) -> None: + def _validate_schema(self, schema: SchemaPath, value: Any) -> None: validator = self.schema_validators_factory.create( schema, format_validators=self.format_validators, @@ -114,7 +117,7 @@ def _validate_schema(self, schema: Spec, value: Any) -> None: def _get_param_or_header( self, - param_or_header: Spec, + param_or_header: SchemaPath, location: Mapping[str, Any], name: Optional[str] = None, ) -> Any: @@ -131,7 +134,7 @@ def _get_param_or_header( def _get_simple_param_or_header( self, - param_or_header: Spec, + param_or_header: SchemaPath, location: Mapping[str, Any], name: Optional[str] = None, ) -> Any: @@ -147,7 +150,7 @@ def _get_simple_param_or_header( def _get_complex_param_or_header( self, - param_or_header: Spec, + param_or_header: SchemaPath, location: Mapping[str, Any], name: Optional[str] = None, ) -> Any: @@ -160,7 +163,7 @@ def _get_complex_param_or_header( def _convert_schema_style_value( self, raw: Any, - param_or_header: Spec, + param_or_header: SchemaPath, ) -> Any: casted, schema = self._convert_schema_style_value_and_schema( raw, param_or_header @@ -171,7 +174,7 @@ def _convert_schema_style_value( return casted def _convert_content_schema_value( - self, raw: Any, content: Spec, mimetype: Optional[str] = None + self, raw: Any, content: SchemaPath, mimetype: Optional[str] = None ) -> Any: casted, schema = self._convert_content_schema_value_and_schema( raw, content, mimetype @@ -184,8 +187,8 @@ def _convert_content_schema_value( def _convert_schema_style_value_and_schema( self, raw: Any, - param_or_header: Spec, - ) -> Tuple[Any, Spec]: + param_or_header: SchemaPath, + ) -> Tuple[Any, SchemaPath]: deserialised = self._deserialise_style(param_or_header, raw) schema = param_or_header / "schema" casted = self._cast(schema, deserialised) @@ -194,9 +197,9 @@ def _convert_schema_style_value_and_schema( def _convert_content_schema_value_and_schema( self, raw: Any, - content: Spec, + content: SchemaPath, mimetype: Optional[str] = None, - ) -> Tuple[Any, Optional[Spec]]: + ) -> Tuple[Any, Optional[SchemaPath]]: mime_type, parameters, media_type = self._find_media_type( content, mimetype ) @@ -211,7 +214,7 @@ def _convert_content_schema_value_and_schema( def _get_style_value( self, - param_or_header: Spec, + param_or_header: SchemaPath, location: Mapping[str, Any], name: Optional[str] = None, ) -> Any: @@ -241,7 +244,7 @@ def _get_style_value( def _get_media_type_value( self, - param_or_header: Spec, + param_or_header: SchemaPath, location: Mapping[str, Any], name: Optional[str] = None, ) -> Any: diff --git a/poetry.lock b/poetry.lock index fb50ce31..e29c0e97 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1016,6 +1016,23 @@ rpds-py = ">=0.7.1" format = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3987", "uri-template", "webcolors (>=1.11)"] format-nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3986-validator (>0.1.0)", "uri-template", "webcolors (>=1.11)"] +[[package]] +name = "jsonschema-path" +version = "0.3.1" +description = "JSONSchema Spec with object-oriented paths" +optional = false +python-versions = ">=3.8.0,<4.0.0" +files = [ + {file = "jsonschema_path-0.3.1-py3-none-any.whl", hash = "sha256:06f01b1848a28963f49a17730e11204d252aa6ff5db4ef84ec77e5ac93cfa831"}, + {file = "jsonschema_path-0.3.1.tar.gz", hash = "sha256:07ea584b5c9b41a614b4d011c5575955676f48d0abbfd93d9ea8e933018d716d"}, +] + +[package.dependencies] +pathable = ">=0.4.1,<0.5.0" +PyYAML = ">=5.1" +referencing = ">=0.28.0,<0.31.0" +requests = ">=2.31.0,<3.0.0" + [[package]] name = "jsonschema-spec" version = "0.2.4" @@ -2468,4 +2485,4 @@ starlette = ["starlette"] [metadata] lock-version = "2.0" python-versions = "^3.8.0" -content-hash = "639a78f65aa5cf9b6f54c1eef10bd159cda3b76b49d85660978c9be4f7f3d5c3" +content-hash = "c4e8bc0763a0b3f061e7e42a49a0f43cbc4666ef6b31fe748ca83d88e55d9b3c" diff --git a/pyproject.toml b/pyproject.toml index 668d31c2..dcaa6af3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ openapi-schema-validator = "^0.6.0" openapi-spec-validator = ">=0.6.0,<0.8.0" requests = {version = "*", optional = true} werkzeug = "*" -jsonschema-spec = "^0.2.3" +jsonschema-path = "^0.3.1" asgiref = "^3.6.0" jsonschema = "^4.18.0" multidict = {version = "^6.0.4", optional = true} diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 7d4db1f7..00dc26b6 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -3,11 +3,10 @@ from urllib import request import pytest +from jsonschema_path import SchemaPath from openapi_spec_validator.readers import read_from_filename from yaml import safe_load -from openapi_core.spec import Spec - def content_from_file(spec_file): directory = path.abspath(path.dirname(__file__)) @@ -17,13 +16,13 @@ def content_from_file(spec_file): def spec_from_file(spec_file): spec_dict, base_uri = content_from_file(spec_file) - return Spec.from_dict(spec_dict, base_uri=base_uri) + return SchemaPath.from_dict(spec_dict, base_uri=base_uri) def spec_from_url(base_uri): content = request.urlopen(base_uri) spec_dict = safe_load(content) - return Spec.from_dict(spec_dict, base_uri=base_uri) + return SchemaPath.from_dict(spec_dict, base_uri=base_uri) @pytest.fixture(scope="session") @@ -62,4 +61,4 @@ def v30_petstore_content(factory): @pytest.fixture(scope="session") def v30_petstore_spec(v30_petstore_content): base_uri = "file://tests/integration/data/v3.0/petstore.yaml" - return Spec.from_dict(v30_petstore_content, base_uri=base_uri) + return SchemaPath.from_dict(v30_petstore_content, base_uri=base_uri) diff --git a/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/openapi.py b/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/openapi.py index 74119263..ac65a703 100644 --- a/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/openapi.py +++ b/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/openapi.py @@ -1,9 +1,8 @@ from pathlib import Path import yaml - -from openapi_core import Spec +from jsonschema_path import SchemaPath openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml") spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader) -spec = Spec.from_dict(spec_dict) +spec = SchemaPath.from_dict(spec_dict) diff --git a/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py b/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py index 5ca14343..0ef34e6e 100644 --- a/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py +++ b/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py @@ -14,8 +14,7 @@ from pathlib import Path import yaml - -from openapi_core import Spec +from jsonschema_path import SchemaPath # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -123,4 +122,4 @@ OPENAPI_SPEC_DICT = yaml.load(OPENAPI_SPEC_PATH.read_text(), yaml.Loader) -OPENAPI_SPEC = Spec.from_dict(OPENAPI_SPEC_DICT) +OPENAPI_SPEC = SchemaPath.from_dict(OPENAPI_SPEC_DICT) diff --git a/tests/integration/contrib/falcon/data/v3.0/falconproject/openapi.py b/tests/integration/contrib/falcon/data/v3.0/falconproject/openapi.py index 2676ba21..3fd65641 100644 --- a/tests/integration/contrib/falcon/data/v3.0/falconproject/openapi.py +++ b/tests/integration/contrib/falcon/data/v3.0/falconproject/openapi.py @@ -1,13 +1,13 @@ from pathlib import Path import yaml +from jsonschema_path import SchemaPath -from openapi_core import Spec from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml") spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader) -spec = Spec.from_dict(spec_dict) +spec = SchemaPath.from_dict(spec_dict) openapi_middleware = FalconOpenAPIMiddleware.from_spec( spec, extra_media_type_deserializers={}, diff --git a/tests/integration/contrib/flask/data/v3.0/flaskproject/openapi.py b/tests/integration/contrib/flask/data/v3.0/flaskproject/openapi.py index 0f787e09..6a4daea8 100644 --- a/tests/integration/contrib/flask/data/v3.0/flaskproject/openapi.py +++ b/tests/integration/contrib/flask/data/v3.0/flaskproject/openapi.py @@ -1,10 +1,10 @@ from pathlib import Path import yaml +from jsonschema_path import SchemaPath -from openapi_core import Spec from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml") spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader) -spec = Spec.from_dict(spec_dict) +spec = SchemaPath.from_dict(spec_dict) diff --git a/tests/integration/contrib/starlette/data/v3.0/starletteproject/openapi.py b/tests/integration/contrib/starlette/data/v3.0/starletteproject/openapi.py index 74119263..ac65a703 100644 --- a/tests/integration/contrib/starlette/data/v3.0/starletteproject/openapi.py +++ b/tests/integration/contrib/starlette/data/v3.0/starletteproject/openapi.py @@ -1,9 +1,8 @@ from pathlib import Path import yaml - -from openapi_core import Spec +from jsonschema_path import SchemaPath openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml") spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader) -spec = Spec.from_dict(spec_dict) +spec = SchemaPath.from_dict(spec_dict) diff --git a/tests/integration/schema/test_empty.py b/tests/integration/schema/test_empty.py index 0b0435a5..bf2c3132 100644 --- a/tests/integration/schema/test_empty.py +++ b/tests/integration/schema/test_empty.py @@ -1,10 +1,11 @@ import pytest from openapi_spec_validator.validation.exceptions import ValidatorDetectError -from openapi_core.spec import Spec +from openapi_core import Spec class TestEmpty: def test_raises_on_invalid(self): - with pytest.raises(ValidatorDetectError): - Spec.from_dict("") + with pytest.warns(DeprecationWarning): + with pytest.raises(ValidatorDetectError): + Spec.from_dict("") diff --git a/tests/integration/schema/test_spec.py b/tests/integration/schema/test_spec.py index 5432b358..60eff027 100644 --- a/tests/integration/schema/test_spec.py +++ b/tests/integration/schema/test_spec.py @@ -1,10 +1,8 @@ from base64 import b64encode import pytest -from openapi_spec_validator import openapi_v30_spec_validator -from openapi_spec_validator import openapi_v31_spec_validator +from jsonschema_path import SchemaPath -from openapi_core import Spec from openapi_core import V30RequestValidator from openapi_core import V30ResponseValidator from openapi_core.schema.servers import get_server_url @@ -31,9 +29,7 @@ def spec_dict(self, factory): @pytest.fixture def spec(self, spec_dict, base_uri): - return Spec.from_dict( - spec_dict, base_uri=base_uri, validator=openapi_v30_spec_validator - ) + return SchemaPath.from_dict(spec_dict, base_uri=base_uri) @pytest.fixture def request_validator(self, spec): @@ -324,10 +320,9 @@ def spec_dict(self, factory): @pytest.fixture def spec(self, spec_dict, base_uri): - return Spec.from_dict( + return SchemaPath.from_dict( spec_dict, base_uri=base_uri, - validator=openapi_v31_spec_validator, ) @pytest.fixture diff --git a/tests/integration/unmarshalling/test_unmarshallers.py b/tests/integration/unmarshalling/test_unmarshallers.py index 274fa732..7efb8ed9 100644 --- a/tests/integration/unmarshalling/test_unmarshallers.py +++ b/tests/integration/unmarshalling/test_unmarshallers.py @@ -8,8 +8,8 @@ from isodate.tzinfo import FixedOffset from jsonschema.exceptions import SchemaError from jsonschema.exceptions import UnknownType +from jsonschema_path import SchemaPath -from openapi_core import Spec from openapi_core.unmarshalling.schemas import ( oas30_read_schema_unmarshallers_factory, ) @@ -34,7 +34,7 @@ def test_create_schema_deprecated(self, unmarshallers_factory): schema = { "deprecated": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.warns(DeprecationWarning): unmarshallers_factory.create(spec) @@ -44,7 +44,7 @@ def test_create_formatter_not_found(self, unmarshallers_factory): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises( FormatterNotFoundError, @@ -66,7 +66,7 @@ def test_create_formatter_not_found(self, unmarshallers_factory): ) def test_no_type(self, unmarshallers_factory, value): schema = {} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -89,7 +89,7 @@ def test_basic_types(self, unmarshallers_factory, type, value): schema = { "type": type, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -144,7 +144,7 @@ def test_basic_types_invalid(self, unmarshallers_factory, type, value): schema = { "type": type, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises( @@ -190,7 +190,7 @@ def test_basic_formats( schema = { "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -233,7 +233,7 @@ def test_basic_type_formats( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -257,7 +257,7 @@ def test_basic_type_formats_ignored( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -279,7 +279,7 @@ def test_basic_type_formats_invalid( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -300,7 +300,7 @@ def test_string_byte(self, unmarshallers_factory, value, expected): "type": "string", "format": "byte", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -312,7 +312,7 @@ def test_string_date(self, unmarshallers_factory): "type": "string", "format": "date", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "2018-01-02" @@ -335,7 +335,7 @@ def test_string_datetime(self, unmarshallers_factory, value, expected): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -347,7 +347,7 @@ def test_string_datetime_invalid(self, unmarshallers_factory): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "2018-01-02T00:00:00" @@ -363,7 +363,7 @@ def test_string_password(self, unmarshallers_factory): "type": "string", "format": "password", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "passwd" @@ -376,7 +376,7 @@ def test_string_uuid(self, unmarshallers_factory): "type": "string", "format": "uuid", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = str(uuid4()) @@ -389,7 +389,7 @@ def test_string_uuid_invalid(self, unmarshallers_factory): "type": "string", "format": "uuid", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "test" @@ -418,7 +418,7 @@ def test_formats_ignored( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -431,7 +431,7 @@ def test_string_pattern(self, unmarshallers_factory, value): "type": "string", "pattern": "bar", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -452,7 +452,7 @@ def test_string_pattern_invalid( "type": "string", "pattern": pattern, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -469,7 +469,7 @@ def test_string_min_length(self, unmarshallers_factory, value): "type": "string", "minLength": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -482,7 +482,7 @@ def test_string_min_length_invalid(self, unmarshallers_factory, value): "type": "string", "minLength": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -499,7 +499,7 @@ def test_string_max_length(self, unmarshallers_factory, value): "type": "string", "maxLength": 1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -512,7 +512,7 @@ def test_string_max_length_invalid(self, unmarshallers_factory, value): "type": "string", "maxLength": 1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -535,7 +535,7 @@ def test_string_max_length_invalid_schema( "type": "string", "maxLength": -1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -546,7 +546,7 @@ def test_integer_enum(self, unmarshallers_factory): "type": "integer", "enum": [1, 2, 3], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = 2 @@ -560,7 +560,7 @@ def test_integer_enum_invalid(self, unmarshallers_factory): "type": "integer", "enum": enum, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = 12 @@ -591,7 +591,7 @@ def test_array(self, unmarshallers_factory, type, value): "type": type, }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value_list = [value] * 3 @@ -617,7 +617,7 @@ def test_array_invalid(self, unmarshallers_factory, type, value): "type": type, }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -637,7 +637,7 @@ def test_array_min_items_invalid(self, unmarshallers_factory, value): }, "minItems": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -656,7 +656,7 @@ def test_array_min_items(self, unmarshallers_factory, value): }, "minItems": 0, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -679,7 +679,7 @@ def test_array_max_items_invalid_schema( }, "maxItems": -1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -694,7 +694,7 @@ def test_array_max_items_invalid(self, unmarshallers_factory, value): }, "maxItems": 1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -713,7 +713,7 @@ def test_array_unique_items_invalid(self, unmarshallers_factory, value): }, "uniqueItems": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -740,7 +740,7 @@ def test_object_any_of(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = {"someint": 1} @@ -764,7 +764,7 @@ def test_object_any_of_invalid(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -799,7 +799,7 @@ def test_object_one_of_default(self, unmarshallers_factory): }, }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) assert unmarshaller.unmarshal({"someint": 1}) == { @@ -830,7 +830,7 @@ def test_object_any_of_default(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) assert unmarshaller.unmarshal({"someint": "1"}) == { @@ -862,7 +862,7 @@ def test_object_all_of_default(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) assert unmarshaller.unmarshal({}) == { @@ -897,7 +897,7 @@ def test_object_with_properties(self, unmarshallers_factory, value): }, }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -941,7 +941,7 @@ def test_object_with_properties_invalid( }, "additionalProperties": False, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -963,7 +963,7 @@ def test_object_default_property(self, unmarshallers_factory, value): } }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -983,7 +983,7 @@ def test_object_additional_properties_false( "type": "object", "additionalProperties": False, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1005,7 +1005,7 @@ def test_object_additional_properties_free_form_object( "type": "object", "additionalProperties": additional_properties, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1014,7 +1014,7 @@ def test_object_additional_properties_free_form_object( def test_object_additional_properties_list(self, unmarshallers_factory): schema = {"type": "object"} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal({"user_ids": [1, 2, 3, 4]}) @@ -1033,7 +1033,7 @@ def test_object_additional_properties(self, unmarshallers_factory, value): schema = { "type": "object", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1056,7 +1056,7 @@ def test_object_additional_properties_object( "type": "object", "additionalProperties": additional_properties, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1077,7 +1077,7 @@ def test_object_min_properties(self, unmarshallers_factory, value): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "minProperties": 1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1098,7 +1098,7 @@ def test_object_min_properties_invalid(self, unmarshallers_factory, value): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "minProperties": 4, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1117,7 +1117,7 @@ def test_object_min_properties_invalid_schema( "type": "object", "minProperties": 2, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1137,7 +1137,7 @@ def test_object_max_properties(self, unmarshallers_factory, value): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "maxProperties": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1158,7 +1158,7 @@ def test_object_max_properties_invalid(self, unmarshallers_factory, value): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "maxProperties": 0, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1177,7 +1177,7 @@ def test_object_max_properties_invalid_schema( "type": "object", "maxProperties": -1, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1197,7 +1197,7 @@ def test_any_one_of(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = ["hello"] @@ -1219,7 +1219,7 @@ def test_any_any_of(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = ["hello"] @@ -1238,7 +1238,7 @@ def test_any_all_of(self, unmarshallers_factory): } ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = ["hello"] @@ -1292,7 +1292,7 @@ def test_any_all_of_invalid_properties(self, value, unmarshallers_factory): ], "additionalProperties": False, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1308,7 +1308,7 @@ def test_any_format_one_of(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "2018-01-02" @@ -1326,7 +1326,7 @@ def test_any_one_of_any(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "2018-01-02" @@ -1344,7 +1344,7 @@ def test_any_any_of_any(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "2018-01-02" @@ -1362,7 +1362,7 @@ def test_any_all_of_any(self, unmarshallers_factory): }, ], } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = "2018-01-02" @@ -1400,7 +1400,7 @@ def test_any_of_no_valid(self, unmarshallers_factory, value): schema = { "anyOf": any_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1440,7 +1440,7 @@ def test_any_one_of_no_valid(self, unmarshallers_factory, value): schema = { "oneOf": one_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1457,7 +1457,7 @@ def test_any_any_of_different_type(self, unmarshallers_factory, value): schema = { "anyOf": any_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1481,7 +1481,7 @@ def test_any_one_of_different_type(self, unmarshallers_factory, value): schema = { "oneOf": one_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1528,7 +1528,7 @@ def test_any_any_of_unambiguous(self, unmarshallers_factory, value): schema = { "anyOf": any_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1554,7 +1554,7 @@ def test_object_multiple_any_of(self, unmarshallers_factory, value): "type": "object", "anyOf": any_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1580,7 +1580,7 @@ def test_object_multiple_one_of(self, unmarshallers_factory, value): "type": "object", "oneOf": one_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue): @@ -1629,7 +1629,7 @@ def test_any_one_of_unambiguous(self, unmarshallers_factory, value): schema = { "oneOf": one_of, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1640,7 +1640,7 @@ def test_any_one_of_unambiguous(self, unmarshallers_factory, value): class BaseTestOASS30chemaUnmarshallersFactoryCall: def test_null_undefined(self, unmarshallers_factory): schema = {"type": "null"} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(UnknownType): @@ -1658,7 +1658,7 @@ def test_null_undefined(self, unmarshallers_factory): ) def test_nullable(self, unmarshallers_factory, type): schema = {"type": type, "nullable": True} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(None) @@ -1677,7 +1677,7 @@ def test_nullable(self, unmarshallers_factory, type): ) def test_not_nullable(self, unmarshallers_factory, type): schema = {"type": type} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises( @@ -1708,7 +1708,7 @@ def test_basic_type_oas30_formats( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -1729,7 +1729,7 @@ def test_basic_type_oas30_formats_invalid( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises( @@ -1753,7 +1753,7 @@ def test_string_format_binary_invalid(self, unmarshallers_factory): schema = { "type": "string", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = b"true" @@ -1785,7 +1785,7 @@ def test_nultiple_types_undefined( self, unmarshallers_factory, types, value ): schema = {"type": types} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(SchemaError): @@ -1798,7 +1798,7 @@ def test_integer_default_nullable(self, unmarshallers_factory): "default": default_value, "nullable": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = None @@ -1814,7 +1814,7 @@ def test_array_nullable(self, unmarshallers_factory): }, "nullable": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = None @@ -1832,7 +1832,7 @@ def test_object_property_nullable(self, unmarshallers_factory): } }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = {"foo": None} @@ -1860,7 +1860,7 @@ def test_write_only_properties(self, unmarshallers_factory): } }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = {"id": 10} @@ -1880,7 +1880,7 @@ def test_read_only_properties_invalid(self, unmarshallers_factory): } }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) value = {"id": 10} @@ -1908,7 +1908,7 @@ def test_read_only_properties(self, unmarshallers_factory): } }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) # readOnly properties may be admitted in a Response context @@ -1929,7 +1929,7 @@ def test_write_only_properties_invalid(self, unmarshallers_factory): } }, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) # readOnly properties are not admitted on a Request context @@ -1965,7 +1965,7 @@ def test_create_oas30_formatter_not_found( "type": type, "format": format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(FormatterNotFoundError): unmarshallers_factory.create(spec) @@ -1985,7 +1985,7 @@ def test_basic_types_invalid(self, unmarshallers_factory, type, value): schema = { "type": type, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises( @@ -1996,7 +1996,7 @@ def test_basic_types_invalid(self, unmarshallers_factory, type, value): def test_null(self, unmarshallers_factory): schema = {"type": "null"} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(None) @@ -2006,7 +2006,7 @@ def test_null(self, unmarshallers_factory): @pytest.mark.parametrize("value", ["string", 2, 3.14, True, [1, 2], {}]) def test_null_invalid(self, unmarshallers_factory, value): schema = {"type": "null"} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -2029,7 +2029,7 @@ def test_null_invalid(self, unmarshallers_factory, value): ) def test_nultiple_types(self, unmarshallers_factory, types, value): schema = {"type": types} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(value) @@ -2049,7 +2049,7 @@ def test_nultiple_types(self, unmarshallers_factory, types, value): ) def test_nultiple_types_invalid(self, unmarshallers_factory, types, value): schema = {"type": types} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) with pytest.raises(InvalidSchemaValue) as exc_info: @@ -2059,7 +2059,7 @@ def test_nultiple_types_invalid(self, unmarshallers_factory, types, value): def test_any_null(self, unmarshallers_factory): schema = {} - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) unmarshaller = unmarshallers_factory.create(spec) result = unmarshaller.unmarshal(None) diff --git a/tests/unit/casting/test_schema_casters.py b/tests/unit/casting/test_schema_casters.py index e03d06cf..cb14a23a 100644 --- a/tests/unit/casting/test_schema_casters.py +++ b/tests/unit/casting/test_schema_casters.py @@ -1,8 +1,8 @@ import pytest +from jsonschema_path import SchemaPath from openapi_core.casting.schemas.exceptions import CastError from openapi_core.casting.schemas.factories import SchemaCastersFactory -from openapi_core.spec.paths import Spec class TestSchemaCaster: @@ -20,7 +20,7 @@ def test_array_invalid_type(self, caster_factory): "type": "number", }, } - schema = Spec.from_dict(spec, validator=None) + schema = SchemaPath.from_dict(spec) value = ["test", "test2"] with pytest.raises(CastError): @@ -34,7 +34,7 @@ def test_array_invalid_value(self, value, caster_factory): "oneOf": [{"type": "number"}, {"type": "string"}], }, } - schema = Spec.from_dict(spec, validator=None) + schema = SchemaPath.from_dict(spec) with pytest.raises( CastError, match=f"Failed to cast value to array type: {value}" diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index ea3361fb..1136240f 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,18 +1,17 @@ import pytest - -from openapi_core import Spec +from jsonschema_path import SchemaPath @pytest.fixture def spec_v30(): - return Spec.from_dict({"openapi": "3.0"}, validator=None) + return SchemaPath.from_dict({"openapi": "3.0"}) @pytest.fixture def spec_v31(): - return Spec.from_dict({"openapi": "3.1"}, validator=None) + return SchemaPath.from_dict({"openapi": "3.1"}) @pytest.fixture def spec_invalid(): - return Spec.from_dict({}, validator=None) + return SchemaPath.from_dict({}) diff --git a/tests/unit/deserializing/test_styles_deserializers.py b/tests/unit/deserializing/test_styles_deserializers.py index 9d4d7094..eed4130e 100644 --- a/tests/unit/deserializing/test_styles_deserializers.py +++ b/tests/unit/deserializing/test_styles_deserializers.py @@ -1,4 +1,5 @@ import pytest +from jsonschema_path import SchemaPath from openapi_core.deserializing.styles.exceptions import ( EmptyQueryParameterValue, @@ -6,7 +7,6 @@ from openapi_core.deserializing.styles.factories import ( StyleDeserializersFactory, ) -from openapi_core.spec.paths import Spec class TestStyleDeserializer: @@ -19,7 +19,7 @@ def create_deserializer(param): def test_unsupported(self, deserializer_factory): spec = {"name": "param", "in": "header", "style": "unsupported"} - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) deserializer = deserializer_factory(param) value = "" @@ -33,7 +33,7 @@ def test_query_empty(self, deserializer_factory): "name": "param", "in": "query", } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) deserializer = deserializer_factory(param) value = "" @@ -45,7 +45,7 @@ def test_query_valid(self, deserializer_factory): "name": "param", "in": "query", } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) deserializer = deserializer_factory(param) value = "test" diff --git a/tests/unit/extensions/test_factories.py b/tests/unit/extensions/test_factories.py index 3ed718c5..d50fd551 100644 --- a/tests/unit/extensions/test_factories.py +++ b/tests/unit/extensions/test_factories.py @@ -5,9 +5,9 @@ from typing import Any import pytest +from jsonschema_path import SchemaPath from openapi_core.extensions.models.factories import ModelPathFactory -from openapi_core.spec import Spec class TestImportModelCreate: @@ -27,7 +27,7 @@ class BarModel: def test_dynamic_model(self): factory = ModelPathFactory() - schema = Spec.from_dict({"x-model": "TestModel"}, validator=None) + schema = SchemaPath.from_dict({"x-model": "TestModel"}) test_model_class = factory.create(schema, ["name"]) assert is_dataclass(test_model_class) @@ -38,9 +38,7 @@ def test_dynamic_model(self): def test_model_path(self, loaded_model_class): factory = ModelPathFactory() - schema = Spec.from_dict( - {"x-model-path": "foo.BarModel"}, validator=None - ) + schema = SchemaPath.from_dict({"x-model-path": "foo.BarModel"}) test_model_class = factory.create(schema, ["a", "b"]) assert test_model_class == loaded_model_class diff --git a/tests/unit/schema/test_schema_parameters.py b/tests/unit/schema/test_schema_parameters.py index 4993ddb6..3436889c 100644 --- a/tests/unit/schema/test_schema_parameters.py +++ b/tests/unit/schema/test_schema_parameters.py @@ -1,8 +1,8 @@ import pytest +from jsonschema_path import SchemaPath from openapi_core.schema.parameters import get_explode from openapi_core.schema.parameters import get_style -from openapi_core.spec.paths import Spec class TestGetStyle: @@ -20,7 +20,7 @@ def test_defaults(self, location, expected): "name": "default", "in": location, } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) result = get_style(param) assert result == expected @@ -45,7 +45,7 @@ def test_defined(self, style, location): "in": location, "style": style, } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) result = get_style(param) assert result == style @@ -69,7 +69,7 @@ def test_defaults_false(self, style, location): "in": location, "style": style, } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) result = get_explode(param) assert result is False @@ -81,7 +81,7 @@ def test_defaults_true(self, location): "in": location, "style": "form", } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) result = get_explode(param) assert result is True @@ -117,7 +117,7 @@ def test_defined(self, location, style, schema_type, explode): "type": schema_type, }, } - param = Spec.from_dict(spec, validator=None) + param = SchemaPath.from_dict(spec) result = get_explode(param) assert result == explode diff --git a/tests/unit/security/test_providers.py b/tests/unit/security/test_providers.py index e75ed371..56f5990f 100644 --- a/tests/unit/security/test_providers.py +++ b/tests/unit/security/test_providers.py @@ -1,7 +1,7 @@ import pytest +from jsonschema_path import SchemaPath from openapi_core.security.providers import HttpProvider -from openapi_core.spec.paths import Spec from openapi_core.testing import MockRequest @@ -32,7 +32,7 @@ def test_header(self, header, scheme): "/pets", headers=headers, ) - scheme = Spec.from_dict(spec, validator=None) + scheme = SchemaPath.from_dict(spec) provider = HttpProvider(scheme) result = provider(request.parameters) diff --git a/tests/unit/templating/test_media_types_finders.py b/tests/unit/templating/test_media_types_finders.py index 62adfdae..9580c30c 100644 --- a/tests/unit/templating/test_media_types_finders.py +++ b/tests/unit/templating/test_media_types_finders.py @@ -1,6 +1,6 @@ import pytest +from jsonschema_path import SchemaPath -from openapi_core.spec.paths import Spec from openapi_core.templating.media_types.exceptions import MediaTypeNotFound from openapi_core.templating.media_types.finders import MediaTypeFinder from openapi_core.testing import MockResponse @@ -16,7 +16,7 @@ def spec(self): @pytest.fixture(scope="class") def content(self, spec): - return Spec.from_dict(spec, validator=None) + return SchemaPath.from_dict(spec) @pytest.fixture(scope="class") def finder(self, content): diff --git a/tests/unit/templating/test_paths_finders.py b/tests/unit/templating/test_paths_finders.py index e26e70c7..cb0821ee 100644 --- a/tests/unit/templating/test_paths_finders.py +++ b/tests/unit/templating/test_paths_finders.py @@ -1,6 +1,6 @@ import pytest +from jsonschema_path import SchemaPath -from openapi_core.spec.paths import Spec from openapi_core.templating.datatypes import TemplateResult from openapi_core.templating.paths.exceptions import OperationNotFound from openapi_core.templating.paths.exceptions import PathNotFound @@ -124,7 +124,7 @@ def spec(self, info, paths, servers): "servers": servers, "paths": paths, } - return Spec.from_dict(spec, validator=None) + return SchemaPath.from_dict(spec) @pytest.fixture def finder(self, spec): @@ -146,7 +146,7 @@ def spec(self, info, paths): "info": info, "paths": paths, } - return Spec.from_dict(spec, validator=None) + return SchemaPath.from_dict(spec) class BaseTestOperationServer(BaseTestSpecServer): @@ -165,7 +165,7 @@ def spec(self, info, paths): "info": info, "paths": paths, } - return Spec.from_dict(spec, validator=None) + return SchemaPath.from_dict(spec) class BaseTestServerNotFound: @@ -281,7 +281,7 @@ def spec(self, info): spec = { "info": info, } - return Spec.from_dict(spec, validator=None) + return SchemaPath.from_dict(spec) def test_raises(self, finder): method = "get" diff --git a/tests/unit/templating/test_responses_finders.py b/tests/unit/templating/test_responses_finders.py index a5b62909..5aac4fbc 100644 --- a/tests/unit/templating/test_responses_finders.py +++ b/tests/unit/templating/test_responses_finders.py @@ -1,8 +1,8 @@ from unittest import mock import pytest +from jsonschema_path import SchemaPath -from openapi_core.spec.paths import Spec from openapi_core.templating.responses.finders import ResponseFinder @@ -18,7 +18,7 @@ def spec(self): @pytest.fixture(scope="class") def responses(self, spec): - return Spec.from_dict(spec, validator=None) + return SchemaPath.from_dict(spec) @pytest.fixture(scope="class") def finder(self, responses): diff --git a/tests/unit/unmarshalling/test_path_item_params_validator.py b/tests/unit/unmarshalling/test_path_item_params_validator.py index 21695421..cf41e6d9 100644 --- a/tests/unit/unmarshalling/test_path_item_params_validator.py +++ b/tests/unit/unmarshalling/test_path_item_params_validator.py @@ -1,8 +1,8 @@ from dataclasses import is_dataclass import pytest +from jsonschema_path import SchemaPath -from openapi_core import Spec from openapi_core import V30RequestUnmarshaller from openapi_core import unmarshal_request from openapi_core import validate_request @@ -45,7 +45,7 @@ def spec_dict(self): @pytest.fixture(scope="session") def spec(self, spec_dict): - return Spec.from_dict(spec_dict) + return SchemaPath.from_dict(spec_dict) @pytest.fixture(scope="session") def request_unmarshaller(self, spec): diff --git a/tests/unit/unmarshalling/test_schema_unmarshallers.py b/tests/unit/unmarshalling/test_schema_unmarshallers.py index 9d005e99..3373a34f 100644 --- a/tests/unit/unmarshalling/test_schema_unmarshallers.py +++ b/tests/unit/unmarshalling/test_schema_unmarshallers.py @@ -1,9 +1,9 @@ from functools import partial import pytest +from jsonschema_path import SchemaPath from openapi_schema_validator import OAS30WriteValidator -from openapi_core.spec.paths import Spec from openapi_core.unmarshalling.schemas import oas30_types_unmarshaller from openapi_core.unmarshalling.schemas.exceptions import ( FormatterNotFoundError, @@ -56,7 +56,7 @@ def test_string_format_unknown(self, unmarshaller_factory): "type": "string", "format": unknown_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(FormatterNotFoundError): unmarshaller_factory(spec) @@ -67,7 +67,7 @@ def test_string_format_invalid_value(self, unmarshaller_factory): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises( FormatterNotFoundError, @@ -88,7 +88,7 @@ def custom_format_unmarshaller(value): "type": "string", "format": "custom", } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" schema_validators_factory = SchemaValidatorsFactory( OAS30WriteValidator @@ -118,7 +118,7 @@ def custom_format_unmarshaller(value): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" schema_validators_factory = SchemaValidatorsFactory( OAS30WriteValidator @@ -147,7 +147,7 @@ def custom_format_validator(value): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" schema_validators_factory = SchemaValidatorsFactory( OAS30WriteValidator @@ -175,7 +175,7 @@ def custom_format_validator(value): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" schema_validators_factory = SchemaValidatorsFactory( OAS30WriteValidator @@ -208,7 +208,7 @@ def test_schema_format_validator_format_invalid( "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" schema_validators_factory = SchemaValidatorsFactory( OAS30WriteValidator @@ -235,7 +235,7 @@ def custom_format_validator(value): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" schema_validators_factory = SchemaValidatorsFactory( OAS30WriteValidator diff --git a/tests/unit/validation/test_schema_validators.py b/tests/unit/validation/test_schema_validators.py index 099121d1..4732a113 100644 --- a/tests/unit/validation/test_schema_validators.py +++ b/tests/unit/validation/test_schema_validators.py @@ -1,6 +1,6 @@ import pytest +from jsonschema_path import SchemaPath -from openapi_core.spec.paths import Spec from openapi_core.validation.schemas import ( oas30_write_schema_validators_factory, ) @@ -21,7 +21,7 @@ def test_string_format_custom_missing(self, validator_factory): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) value = "x" validator_factory(spec).validate(value) @@ -32,7 +32,7 @@ def test_integer_minimum_invalid(self, value, validator_factory): "type": "integer", "minimum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -43,7 +43,7 @@ def test_integer_minimum(self, value, validator_factory): "type": "integer", "minimum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -55,7 +55,7 @@ def test_integer_maximum_invalid(self, value, validator_factory): "type": "integer", "maximum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -66,7 +66,7 @@ def test_integer_maximum(self, value, validator_factory): "type": "integer", "maximum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -78,7 +78,7 @@ def test_integer_multiple_of_invalid(self, value, validator_factory): "type": "integer", "multipleOf": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -89,7 +89,7 @@ def test_integer_multiple_of(self, value, validator_factory): "type": "integer", "multipleOf": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -101,7 +101,7 @@ def test_number_minimum_invalid(self, value, validator_factory): "type": "number", "minimum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -112,7 +112,7 @@ def test_number_minimum(self, value, validator_factory): "type": "number", "minimum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -125,7 +125,7 @@ def test_number_exclusive_minimum_invalid(self, value, validator_factory): "minimum": 3, "exclusiveMinimum": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -137,7 +137,7 @@ def test_number_exclusive_minimum(self, value, validator_factory): "minimum": 3, "exclusiveMinimum": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -149,7 +149,7 @@ def test_number_maximum_invalid(self, value, validator_factory): "type": "number", "maximum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -160,7 +160,7 @@ def test_number_maximum(self, value, validator_factory): "type": "number", "maximum": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -173,7 +173,7 @@ def test_number_exclusive_maximum_invalid(self, value, validator_factory): "maximum": 3, "exclusiveMaximum": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -185,7 +185,7 @@ def test_number_exclusive_maximum(self, value, validator_factory): "maximum": 3, "exclusiveMaximum": True, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value) @@ -197,7 +197,7 @@ def test_number_multiple_of_invalid(self, value, validator_factory): "type": "number", "multipleOf": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -208,7 +208,7 @@ def test_number_multiple_of(self, value, validator_factory): "type": "number", "multipleOf": 3, } - spec = Spec.from_dict(schema, validator=None) + spec = SchemaPath.from_dict(schema) result = validator_factory(spec).validate(value)