From 536fa8d48b084b6099d86ac5dde2a1e8c71a51b8 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Sun, 5 Nov 2023 21:50:06 +0000 Subject: [PATCH] Deprecated spec validator fix --- openapi_core/spec/paths.py | 25 ++- .../unmarshalling/schemas/unmarshallers.py | 4 +- poetry.lock | 29 ++- pyproject.toml | 2 +- .../data/v3.0/djangoproject/settings.py | 2 - .../requests/test_requests_validation.py | 1 - tests/integration/schema/test_spec.py | 10 +- tests/integration/test_petstore.py | 210 +++++++++++------- .../test_request_unmarshaller.py | 8 +- .../unmarshalling/test_unmarshallers.py | 178 +++++++-------- tests/unit/casting/test_schema_casters.py | 4 +- tests/unit/conftest.py | 6 +- .../test_parameters_deserializers.py | 6 +- tests/unit/extensions/test_factories.py | 6 +- tests/unit/schema/test_schema_parameters.py | 10 +- tests/unit/security/test_providers.py | 2 +- .../templating/test_media_types_finders.py | 2 +- tests/unit/templating/test_paths_finders.py | 8 +- .../unit/templating/test_responses_finders.py | 2 +- tests/unit/test_paths_spec.py | 24 ++ .../test_schema_unmarshallers.py | 16 +- .../unit/validation/test_schema_validators.py | 34 +-- 22 files changed, 346 insertions(+), 243 deletions(-) create mode 100644 tests/unit/test_paths_spec.py diff --git a/openapi_core/spec/paths.py b/openapi_core/spec/paths.py index db0aee44..672e8c78 100644 --- a/openapi_core/spec/paths.py +++ b/openapi_core/spec/paths.py @@ -1,11 +1,13 @@ +import warnings from typing import Any from typing import Hashable from typing import Mapping from typing import Type from typing import TypeVar +from jsonschema.validators import _UNSET from jsonschema_spec import SchemaPath -from openapi_spec_validator.validation import openapi_spec_validator_proxy +from openapi_spec_validator import validate TSpec = TypeVar("TSpec", bound="Spec") @@ -20,11 +22,22 @@ def from_dict( *args: Any, **kwargs: Any, ) -> TSpec: - validator = kwargs.pop("validator", openapi_spec_validator_proxy) - if validator is not None: - base_uri = kwargs.get("base_uri", "") - spec_url = kwargs.get("spec_url") - validator.validate(data, base_uri=base_uri, spec_url=spec_url) + if "validator" in kwargs: + warnings.warn( + "validator parameter is deprecated. Use spec_validator_cls instead.", + DeprecationWarning, + ) + validator = kwargs.pop("validator", _UNSET) + spec_validator_cls = kwargs.pop("spec_validator_cls", _UNSET) + base_uri = kwargs.get("base_uri", "") + spec_url = kwargs.get("spec_url") + if spec_validator_cls is not None: + if spec_validator_cls is not _UNSET: + validate(data, base_uri=base_uri, cls=spec_validator_cls) + elif validator is _UNSET: + validate(data, base_uri=base_uri) + elif validator is not None: + validator.validate(data, base_uri=base_uri, spec_url=spec_url) return super().from_dict(data, *args, **kwargs) diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 98dffce3..9b0dcdbc 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -45,7 +45,7 @@ def __call__(self, value: Any) -> Optional[List[Any]]: 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", Spec.from_dict({}, spec_validator_cls=None) ) return self.schema_unmarshaller.evolve(items_schema) @@ -120,7 +120,7 @@ def _unmarshal_properties( # free-form object if additional_properties is True: additional_prop_schema = Spec.from_dict( - {"nullable": True}, validator=None + {"nullable": True}, spec_validator_cls=None ) # defined schema else: diff --git a/poetry.lock b/poetry.lock index 4dfb9ae0..971340c1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1041,6 +1041,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" @@ -1381,19 +1398,19 @@ rfc3339-validator = "*" [[package]] name = "openapi-spec-validator" -version = "0.6.0" +version = "0.7.1" description = "OpenAPI 2.0 (aka Swagger) and OpenAPI 3 spec validator" optional = false python-versions = ">=3.8.0,<4.0.0" files = [ - {file = "openapi_spec_validator-0.6.0-py3-none-any.whl", hash = "sha256:675f1a3c0d0d8eff9116694acde88bcd4613a95bf5240270724d9d78c78f26d6"}, - {file = "openapi_spec_validator-0.6.0.tar.gz", hash = "sha256:68c4c212c88ef14c6b1a591b895bf742c455783c7ebba2507abd7dbc1365a616"}, + {file = "openapi_spec_validator-0.7.1-py3-none-any.whl", hash = "sha256:3c81825043f24ccbcd2f4b149b11e8231abce5ba84f37065e14ec947d8f4e959"}, + {file = "openapi_spec_validator-0.7.1.tar.gz", hash = "sha256:8577b85a8268685da6f8aa30990b83b7960d4d1117e901d451b5d572605e5ec7"}, ] [package.dependencies] -importlib-resources = {version = ">=5.8.0,<6.0.0", markers = "python_version < \"3.9\""} +importlib-resources = {version = ">=5.8,<7.0", markers = "python_version < \"3.9\""} jsonschema = ">=4.18.0,<5.0.0" -jsonschema-spec = ">=0.2.3,<0.3.0" +jsonschema-path = ">=0.3.1,<0.4.0" lazy-object-proxy = ">=1.7.1,<2.0.0" openapi-schema-validator = ">=0.6.0,<0.7.0" @@ -2483,4 +2500,4 @@ starlette = ["starlette"] [metadata] lock-version = "2.0" python-versions = "^3.8.0" -content-hash = "80ad9a19a5925d231dfd01e7d7f5637190b54daa5c925e8431ae5cd69333ec25" +content-hash = "ba83953f64ddd115eff950908eaf6ef449ada14079713f75d1c79a7d39f50c7f" diff --git a/pyproject.toml b/pyproject.toml index 7fb5530b..9c362eb8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ isodate = "*" more-itertools = "*" parse = "*" openapi-schema-validator = "^0.6.0" -openapi-spec-validator = "^0.6.0" +openapi-spec-validator = "^0.7.1" requests = {version = "*", optional = true} werkzeug = "*" jsonschema-spec = "^0.2.3" 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..5a5c52b2 100644 --- a/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py +++ b/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py @@ -103,8 +103,6 @@ USE_I18N = True -USE_L10N = True - USE_TZ = True diff --git a/tests/integration/contrib/requests/test_requests_validation.py b/tests/integration/contrib/requests/test_requests_validation.py index 2e8aee8c..8caf34cf 100644 --- a/tests/integration/contrib/requests/test_requests_validation.py +++ b/tests/integration/contrib/requests/test_requests_validation.py @@ -40,7 +40,6 @@ def test_response_validator_path_pattern(self, response_unmarshaller): "http://localhost/browse/12/?q=string", json={"data": "data"}, status=200, - match_querystring=True, headers={"X-Rate-Limit": "12"}, ) request = requests.Request( diff --git a/tests/integration/schema/test_spec.py b/tests/integration/schema/test_spec.py index a0d447c5..44d1795d 100644 --- a/tests/integration/schema/test_spec.py +++ b/tests/integration/schema/test_spec.py @@ -1,8 +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 openapi_spec_validator import OpenAPIV30SpecValidator +from openapi_spec_validator import OpenAPIV31SpecValidator from openapi_core import Spec from openapi_core import V30RequestValidator @@ -32,7 +32,9 @@ 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 + spec_dict, + base_uri=base_uri, + spec_validator_cls=OpenAPIV30SpecValidator, ) @pytest.fixture @@ -327,7 +329,7 @@ def spec(self, spec_dict, base_uri): return Spec.from_dict( spec_dict, base_uri=base_uri, - validator=openapi_v31_spec_validator, + spec_validator_cls=OpenAPIV31SpecValidator, ) @pytest.fixture diff --git a/tests/integration/test_petstore.py b/tests/integration/test_petstore.py index 6a7055d1..de737458 100644 --- a/tests/integration/test_petstore.py +++ b/tests/integration/test_petstore.py @@ -97,11 +97,14 @@ def test_get_pets(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -153,11 +156,14 @@ def test_get_pets_response(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -210,11 +216,14 @@ def test_get_pets_response_no_schema(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -253,11 +262,14 @@ def test_get_pets_invalid_response(self, spec, response_unmarshaller): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -322,11 +334,14 @@ def test_get_pets_ids_param(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -371,11 +386,14 @@ def test_get_pets_tags_param(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -420,12 +438,15 @@ def test_get_pets_parameter_deserialization_error(self, spec): args=query_params, ) - with pytest.raises(ParameterValidationError) as exc_info: - validate_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + with pytest.raises(ParameterValidationError) as exc_info: + validate_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert type(exc_info.value.__cause__) is DeserializeError result = unmarshal_request( @@ -449,12 +470,15 @@ def test_get_pets_wrong_parameter_type(self, spec): args=query_params, ) - with pytest.raises(ParameterValidationError) as exc_info: - validate_request( - request, - spec=spec, - cls=V30RequestParametersValidator, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + with pytest.raises(ParameterValidationError) as exc_info: + validate_request( + request, + spec=spec, + cls=V30RequestParametersValidator, + ) assert type(exc_info.value.__cause__) is CastError result = unmarshal_request( @@ -473,12 +497,15 @@ def test_get_pets_raises_missing_required_param(self, spec): path_pattern=path_pattern, ) - with pytest.raises(MissingRequiredParameter): - validate_request( - request, - spec=spec, - cls=V30RequestParametersValidator, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + with pytest.raises(MissingRequiredParameter): + validate_request( + request, + spec=spec, + cls=V30RequestParametersValidator, + ) result = unmarshal_request( request, spec=spec, cls=V30RequestBodyUnmarshaller @@ -501,12 +528,15 @@ def test_get_pets_empty_value(self, spec): args=query_params, ) - with pytest.raises(ParameterValidationError) as exc_info: - validate_request( - request, - spec=spec, - cls=V30RequestParametersValidator, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + with pytest.raises(ParameterValidationError) as exc_info: + validate_request( + request, + spec=spec, + cls=V30RequestParametersValidator, + ) assert type(exc_info.value.__cause__) is EmptyQueryParameterValue result = unmarshal_request( @@ -531,11 +561,14 @@ def test_get_pets_allow_empty_value(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -566,11 +599,14 @@ def test_get_pets_none_value(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -602,11 +638,14 @@ def test_get_pets_param_order(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert result.parameters == Parameters( query={ @@ -643,11 +682,14 @@ def test_get_pets_param_coordinates(self, spec): args=query_params, ) - result = unmarshal_request( - request, - spec=spec, - cls=V30RequestParametersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="limit parameter is deprecated" + ): + result = unmarshal_request( + request, + spec=spec, + cls=V30RequestParametersUnmarshaller, + ) assert is_dataclass(result.parameters.query["coordinates"]) assert ( @@ -1785,16 +1827,22 @@ def test_delete_tags_with_requestbody(self, spec): } response = MockResponse(data, status_code=200, headers=headers) - response_result = unmarshal_response(request, response, spec=spec) + with pytest.warns( + DeprecationWarning, match="x-delete-confirm header is deprecated" + ): + response_result = unmarshal_response(request, response, spec=spec) assert response_result.errors == [] assert response_result.data is None - result = unmarshal_response( - request, - response, - spec=spec, - cls=V30ResponseHeadersUnmarshaller, - ) + with pytest.warns( + DeprecationWarning, match="x-delete-confirm header is deprecated" + ): + result = unmarshal_response( + request, + response, + spec=spec, + cls=V30ResponseHeadersUnmarshaller, + ) assert result.headers == { "x-delete-confirm": True, diff --git a/tests/integration/unmarshalling/test_request_unmarshaller.py b/tests/integration/unmarshalling/test_request_unmarshaller.py index 62f6ba34..eb4f5a60 100644 --- a/tests/integration/unmarshalling/test_request_unmarshaller.py +++ b/tests/integration/unmarshalling/test_request_unmarshaller.py @@ -116,8 +116,8 @@ def test_get_pets(self, request_unmarshaller): "api_key": self.api_key, } - def test_get_pets_webob(self, request_unmarshaller): - from webob.multidict import GetDict + def test_get_pets_multidict(self, request_unmarshaller): + from multidict import MultiDict request = MockRequest( self.host_url, @@ -125,8 +125,8 @@ def test_get_pets_webob(self, request_unmarshaller): "/v1/pets", path_pattern="/v1/pets", ) - request.parameters.query = GetDict( - [("limit", "5"), ("ids", "1"), ("ids", "2")], {} + request.parameters.query = MultiDict( + [("limit", "5"), ("ids", "1"), ("ids", "2")], ) with pytest.warns(DeprecationWarning): diff --git a/tests/integration/unmarshalling/test_unmarshallers.py b/tests/integration/unmarshalling/test_unmarshallers.py index 274fa732..86addfd6 100644 --- a/tests/integration/unmarshalling/test_unmarshallers.py +++ b/tests/integration/unmarshalling/test_unmarshallers.py @@ -34,7 +34,7 @@ def test_create_schema_deprecated(self, unmarshallers_factory): schema = { "deprecated": True, } - spec = Spec.from_dict(schema, validator=None) + spec = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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..61d4ccdb 100644 --- a/tests/unit/casting/test_schema_casters.py +++ b/tests/unit/casting/test_schema_casters.py @@ -20,7 +20,7 @@ def test_array_invalid_type(self, caster_factory): "type": "number", }, } - schema = Spec.from_dict(spec, validator=None) + schema = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) 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..ba718688 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -5,14 +5,14 @@ @pytest.fixture def spec_v30(): - return Spec.from_dict({"openapi": "3.0"}, validator=None) + return Spec.from_dict({"openapi": "3.0"}, spec_validator_cls=None) @pytest.fixture def spec_v31(): - return Spec.from_dict({"openapi": "3.1"}, validator=None) + return Spec.from_dict({"openapi": "3.1"}, spec_validator_cls=None) @pytest.fixture def spec_invalid(): - return Spec.from_dict({}, validator=None) + return Spec.from_dict({}, spec_validator_cls=None) diff --git a/tests/unit/deserializing/test_parameters_deserializers.py b/tests/unit/deserializing/test_parameters_deserializers.py index 2247dea4..fb1837a0 100644 --- a/tests/unit/deserializing/test_parameters_deserializers.py +++ b/tests/unit/deserializing/test_parameters_deserializers.py @@ -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 = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) deserializer = deserializer_factory(param) value = "test" diff --git a/tests/unit/extensions/test_factories.py b/tests/unit/extensions/test_factories.py index 3ed718c5..d44a643e 100644 --- a/tests/unit/extensions/test_factories.py +++ b/tests/unit/extensions/test_factories.py @@ -27,7 +27,9 @@ class BarModel: def test_dynamic_model(self): factory = ModelPathFactory() - schema = Spec.from_dict({"x-model": "TestModel"}, validator=None) + schema = Spec.from_dict( + {"x-model": "TestModel"}, spec_validator_cls=None + ) test_model_class = factory.create(schema, ["name"]) assert is_dataclass(test_model_class) @@ -39,7 +41,7 @@ def test_model_path(self, loaded_model_class): factory = ModelPathFactory() schema = Spec.from_dict( - {"x-model-path": "foo.BarModel"}, validator=None + {"x-model-path": "foo.BarModel"}, spec_validator_cls=None ) test_model_class = factory.create(schema, ["a", "b"]) diff --git a/tests/unit/schema/test_schema_parameters.py b/tests/unit/schema/test_schema_parameters.py index 4993ddb6..bc64641c 100644 --- a/tests/unit/schema/test_schema_parameters.py +++ b/tests/unit/schema/test_schema_parameters.py @@ -20,7 +20,7 @@ def test_defaults(self, location, expected): "name": "default", "in": location, } - param = Spec.from_dict(spec, validator=None) + param = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) 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 = Spec.from_dict(spec, spec_validator_cls=None) 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..d1466c76 100644 --- a/tests/unit/security/test_providers.py +++ b/tests/unit/security/test_providers.py @@ -32,7 +32,7 @@ def test_header(self, header, scheme): "/pets", headers=headers, ) - scheme = Spec.from_dict(spec, validator=None) + scheme = Spec.from_dict(spec, spec_validator_cls=None) 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 3a93fb94..2b9be711 100644 --- a/tests/unit/templating/test_media_types_finders.py +++ b/tests/unit/templating/test_media_types_finders.py @@ -16,7 +16,7 @@ def spec(self): @pytest.fixture(scope="class") def content(self, spec): - return Spec.from_dict(spec, validator=None) + return Spec.from_dict(spec, spec_validator_cls=None) @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..d9eda904 100644 --- a/tests/unit/templating/test_paths_finders.py +++ b/tests/unit/templating/test_paths_finders.py @@ -124,7 +124,7 @@ def spec(self, info, paths, servers): "servers": servers, "paths": paths, } - return Spec.from_dict(spec, validator=None) + return Spec.from_dict(spec, spec_validator_cls=None) @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 Spec.from_dict(spec, spec_validator_cls=None) class BaseTestOperationServer(BaseTestSpecServer): @@ -165,7 +165,7 @@ def spec(self, info, paths): "info": info, "paths": paths, } - return Spec.from_dict(spec, validator=None) + return Spec.from_dict(spec, spec_validator_cls=None) class BaseTestServerNotFound: @@ -281,7 +281,7 @@ def spec(self, info): spec = { "info": info, } - return Spec.from_dict(spec, validator=None) + return Spec.from_dict(spec, spec_validator_cls=None) 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..8e608e90 100644 --- a/tests/unit/templating/test_responses_finders.py +++ b/tests/unit/templating/test_responses_finders.py @@ -18,7 +18,7 @@ def spec(self): @pytest.fixture(scope="class") def responses(self, spec): - return Spec.from_dict(spec, validator=None) + return Spec.from_dict(spec, spec_validator_cls=None) @pytest.fixture(scope="class") def finder(self, responses): diff --git a/tests/unit/test_paths_spec.py b/tests/unit/test_paths_spec.py new file mode 100644 index 00000000..356f529e --- /dev/null +++ b/tests/unit/test_paths_spec.py @@ -0,0 +1,24 @@ +import pytest +from openapi_spec_validator import openapi_v31_spec_validator +from openapi_spec_validator.validation.exceptions import OpenAPIValidationError +from openapi_core import Spec + + +class TestSpecFromDict: + def test_validator(self): + schema = {} + + with pytest.warns(DeprecationWarning): + with pytest.raises(OpenAPIValidationError): + Spec.from_dict(schema, validator=openapi_v31_spec_validator) + + def test_validator_none(self): + schema = {} + + with pytest.warns(DeprecationWarning): + Spec.from_dict(schema, validator=None) + + def test_spec_validator_cls_none(self): + schema = {} + + Spec.from_dict(schema, spec_validator_cls=None) diff --git a/tests/unit/unmarshalling/test_schema_unmarshallers.py b/tests/unit/unmarshalling/test_schema_unmarshallers.py index 9d005e99..1b3bf9e3 100644 --- a/tests/unit/unmarshalling/test_schema_unmarshallers.py +++ b/tests/unit/unmarshalling/test_schema_unmarshallers.py @@ -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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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..efe932e8 100644 --- a/tests/unit/validation/test_schema_validators.py +++ b/tests/unit/validation/test_schema_validators.py @@ -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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) 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 = Spec.from_dict(schema, spec_validator_cls=None) result = validator_factory(spec).validate(value)