diff --git a/README.rst b/README.rst index 913d158d..acf229f2 100644 --- a/README.rst +++ b/README.rst @@ -62,13 +62,9 @@ Firstly create your specification object. By default, OpenAPI spec version is de .. code-block:: python - from json import load from openapi_core import Spec - with open('openapi.json', 'r') as spec_file: - spec_dict = load(spec_file) - - spec = Spec.create(spec_dict) + spec = Spec.from_file_path('openapi.json') Request ******* diff --git a/docs/customizations.rst b/docs/customizations.rst index fa29517b..d6144002 100644 --- a/docs/customizations.rst +++ b/docs/customizations.rst @@ -4,13 +4,15 @@ Customizations Spec validation --------------- -By default, spec dict is validated on spec creation time. Disabling the validator can improve the performance. +By default, the provided specification is validated on ``Spec`` object creation time. + +If you know you have a valid specification already, disabling the validator can improve the performance. .. code-block:: python from openapi_core import Spec - spec = Spec.create(spec_dict, validator=None) + spec = Spec.from_dict(spec_dict, validator=None) Deserializers ------------- diff --git a/docs/integrations.rst b/docs/integrations.rst index a3227bed..9deb60c0 100644 --- a/docs/integrations.rst +++ b/docs/integrations.rst @@ -28,7 +28,7 @@ Django can be integrated by middleware. Add ``DjangoOpenAPIMiddleware`` to your 'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware', ] - OPENAPI_SPEC = Spec.create(spec_dict) + OPENAPI_SPEC = Spec.from_dict(spec_dict) After that you have access to validation result object with all validated request data from Django view through request object. diff --git a/docs/usage.rst b/docs/usage.rst index 94ccaf20..72d5406e 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -5,13 +5,9 @@ Firstly create your specification object. By default, OpenAPI spec version is de .. code-block:: python - from json import load from openapi_core import Spec - with open('openapi.json', 'r') as spec_file: - spec_dict = load(spec_file) - - spec = Spec.create(spec_dict) + spec = Spec.from_file_path('openapi.json') Request diff --git a/openapi_core/spec/paths.py b/openapi_core/spec/paths.py index ead20691..f6e8228a 100644 --- a/openapi_core/spec/paths.py +++ b/openapi_core/spec/paths.py @@ -1,3 +1,4 @@ +import warnings from typing import Any from typing import Dict from typing import Hashable @@ -27,8 +28,10 @@ def create( separator: str = SPEC_SEPARATOR, validator: Optional[SupportsValidation] = openapi_spec_validator_proxy, ) -> TSpec: - if validator is not None: - validator.validate(data, spec_url=url) + warnings.warn( + "Spec.create method is deprecated. Use Spec.from_dict instead.", + DeprecationWarning, + ) return cls.from_dict( data, @@ -36,4 +39,26 @@ def create( spec_url=url, ref_resolver_handlers=ref_resolver_handlers, separator=separator, + validator=validator, + ) + + @classmethod + def from_dict( + cls: Type[TSpec], + data: Mapping[Hashable, Any], + *args: Any, + spec_url: str = "", + ref_resolver_handlers: Mapping[str, Any] = default_handlers, + separator: str = SPEC_SEPARATOR, + validator: Optional[SupportsValidation] = openapi_spec_validator_proxy, + ) -> TSpec: + if validator is not None: + validator.validate(data, spec_url=spec_url) + + return super().from_dict( + data, + *args, + spec_url=spec_url, + ref_resolver_handlers=ref_resolver_handlers, + separator=separator, ) diff --git a/openapi_core/spec/shortcuts.py b/openapi_core/spec/shortcuts.py index 854e5b95..b8ac1bb4 100644 --- a/openapi_core/spec/shortcuts.py +++ b/openapi_core/spec/shortcuts.py @@ -1,4 +1,5 @@ """OpenAPI core spec shortcuts module""" +import warnings from typing import Any from typing import Dict from typing import Hashable @@ -18,13 +19,18 @@ def create_spec( handlers: Dict[str, Any] = default_handlers, validate_spec: bool = True, ) -> Spec: + warnings.warn( + "create_spec function is deprecated. Use Spec.from_dict instead.", + DeprecationWarning, + ) + validator: Optional[SupportsValidation] = None if validate_spec: validator = openapi_spec_validator_proxy - return Spec.create( + return Spec.from_dict( spec_dict, - url=spec_url, + spec_url=spec_url, ref_resolver_handlers=handlers, validator=validator, ) diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 94baea8c..28e1db88 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -294,7 +294,9 @@ class ArrayUnmarshaller(ComplexUnmarshaller): @property def items_unmarshaller(self) -> "BaseSchemaUnmarshaller": # sometimes we don't have any schema i.e. free-form objects - items_schema = self.schema.get("items", Spec.from_dict({})) + items_schema = self.schema.get( + "items", Spec.from_dict({}, validator=None) + ) return self.unmarshallers_factory.create(items_schema) def unmarshal(self, value: Any) -> Optional[List[Any]]: @@ -383,7 +385,9 @@ 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}) + additional_prop_schema = Spec.from_dict( + {"nullable": True}, validator=None + ) # defined schema else: additional_prop_schema = self.schema / "additionalProperties" diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index e44b90d3..0fe4a4ba 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -16,13 +16,13 @@ def content_from_file(spec_file): def spec_from_file(spec_file): spec_dict, spec_url = content_from_file(spec_file) - return Spec.create(spec_dict, url=spec_url) + return Spec.from_dict(spec_dict, spec_url=spec_url) def spec_from_url(spec_url): content = request.urlopen(spec_url) spec_dict = safe_load(content) - return Spec.create(spec_dict, url=spec_url) + return Spec.from_dict(spec_dict, spec_url=spec_url) class Factory(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 fcfb68d6..5ca14343 100644 --- a/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py +++ b/tests/integration/contrib/django/data/v3.0/djangoproject/settings.py @@ -123,4 +123,4 @@ OPENAPI_SPEC_DICT = yaml.load(OPENAPI_SPEC_PATH.read_text(), yaml.Loader) -OPENAPI_SPEC = Spec.create(OPENAPI_SPEC_DICT) +OPENAPI_SPEC = Spec.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 892aecc0..fbe86d14 100644 --- a/tests/integration/contrib/falcon/data/v3.0/falconproject/openapi.py +++ b/tests/integration/contrib/falcon/data/v3.0/falconproject/openapi.py @@ -7,5 +7,5 @@ openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml") spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader) -spec = Spec.create(spec_dict) +spec = Spec.from_dict(spec_dict) openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec) diff --git a/tests/integration/schema/test_empty.py b/tests/integration/schema/test_empty.py index 9f1f5dfa..0b0435a5 100644 --- a/tests/integration/schema/test_empty.py +++ b/tests/integration/schema/test_empty.py @@ -7,4 +7,4 @@ class TestEmpty: def test_raises_on_invalid(self): with pytest.raises(ValidatorDetectError): - Spec.create("") + Spec.from_dict("") diff --git a/tests/integration/schema/test_spec.py b/tests/integration/schema/test_spec.py index fbca2d81..dbfe7966 100644 --- a/tests/integration/schema/test_spec.py +++ b/tests/integration/schema/test_spec.py @@ -32,8 +32,8 @@ def spec_dict(self, factory): @pytest.fixture def spec(self, spec_dict, spec_uri): - return Spec.create( - spec_dict, url=spec_uri, validator=openapi_v30_spec_validator + return Spec.from_dict( + spec_dict, spec_url=spec_uri, validator=openapi_v30_spec_validator ) @pytest.fixture @@ -325,9 +325,9 @@ def spec_dict(self, factory): @pytest.fixture def spec(self, spec_dict, spec_uri): - return Spec.create( + return Spec.from_dict( spec_dict, - url=spec_uri, + spec_url=spec_uri, validator=openapi_v31_spec_validator, ) diff --git a/tests/integration/validation/test_petstore.py b/tests/integration/validation/test_petstore.py index 456abd76..e617c137 100644 --- a/tests/integration/validation/test_petstore.py +++ b/tests/integration/validation/test_petstore.py @@ -61,7 +61,7 @@ def spec_dict(self, factory): @pytest.fixture(scope="module") def spec(self, spec_dict, spec_uri): - return Spec.create(spec_dict, url=spec_uri) + return Spec.from_dict(spec_dict, spec_url=spec_uri) def test_get_pets(self, spec): host_url = "http://petstore.swagger.io/v1" diff --git a/tests/integration/validation/test_validators.py b/tests/integration/validation/test_validators.py index 57d7d458..4e5c9c7c 100644 --- a/tests/integration/validation/test_validators.py +++ b/tests/integration/validation/test_validators.py @@ -45,7 +45,7 @@ def spec_dict(self, factory): @pytest.fixture(scope="session") def spec(self, spec_dict): - return Spec.create(spec_dict) + return Spec.from_dict(spec_dict) def test_request_server_error(self, spec): request = MockRequest("http://petstore.invalid.net/v1", "get", "/") @@ -443,7 +443,7 @@ def spec_dict(self): @pytest.fixture(scope="session") def spec(self, spec_dict): - return Spec.create(spec_dict) + return Spec.from_dict(spec_dict) def test_request_missing_param(self, spec): request = MockRequest("http://example.com", "get", "/resource") @@ -576,7 +576,7 @@ def spec_dict(self, factory): @pytest.fixture def spec(self, spec_dict): - return Spec.create(spec_dict) + return Spec.from_dict(spec_dict) def test_invalid_server(self, spec): request = MockRequest("http://petstore.invalid.net/v1", "get", "/") diff --git a/tests/unit/casting/test_schema_casters.py b/tests/unit/casting/test_schema_casters.py index 96cc522f..e03d06cf 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) + schema = Spec.from_dict(spec, validator=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) + schema = Spec.from_dict(spec, validator=None) with pytest.raises( CastError, match=f"Failed to cast value to array type: {value}" diff --git a/tests/unit/deserializing/test_parameters_deserializers.py b/tests/unit/deserializing/test_parameters_deserializers.py index 865bfa3b..4e2ffd88 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) + param = Spec.from_dict(spec, validator=None) value = "" with pytest.warns(UserWarning): @@ -32,7 +32,7 @@ def test_query_empty(self, deserializer_factory): "name": "param", "in": "query", } - param = Spec.from_dict(spec) + param = Spec.from_dict(spec, validator=None) value = "" with pytest.raises(EmptyQueryParameterValue): @@ -43,7 +43,7 @@ def test_query_valid(self, deserializer_factory): "name": "param", "in": "query", } - param = Spec.from_dict(spec) + param = Spec.from_dict(spec, validator=None) value = "test" result = deserializer_factory(param)(value) diff --git a/tests/unit/extensions/test_factories.py b/tests/unit/extensions/test_factories.py index 66bf357f..3ed718c5 100644 --- a/tests/unit/extensions/test_factories.py +++ b/tests/unit/extensions/test_factories.py @@ -27,7 +27,7 @@ class BarModel: def test_dynamic_model(self): factory = ModelPathFactory() - schema = Spec.from_dict({"x-model": "TestModel"}) + schema = Spec.from_dict({"x-model": "TestModel"}, validator=None) test_model_class = factory.create(schema, ["name"]) assert is_dataclass(test_model_class) @@ -38,7 +38,9 @@ def test_dynamic_model(self): def test_model_path(self, loaded_model_class): factory = ModelPathFactory() - schema = Spec.from_dict({"x-model-path": "foo.BarModel"}) + schema = Spec.from_dict( + {"x-model-path": "foo.BarModel"}, validator=None + ) 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 95cc2762..4993ddb6 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) + param = Spec.from_dict(spec, validator=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) + param = Spec.from_dict(spec, validator=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) + param = Spec.from_dict(spec, validator=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) + param = Spec.from_dict(spec, validator=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) + param = Spec.from_dict(spec, validator=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 4a982bd9..8f110c5a 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) + scheme = Spec.from_dict(spec, validator=None) provider = HttpProvider(scheme) result = provider(request) diff --git a/tests/unit/templating/test_media_types_finders.py b/tests/unit/templating/test_media_types_finders.py index 74436b22..3a93fb94 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) + return Spec.from_dict(spec, validator=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 cb1cdff7..7c410cd8 100644 --- a/tests/unit/templating/test_paths_finders.py +++ b/tests/unit/templating/test_paths_finders.py @@ -128,7 +128,7 @@ def spec(self, info, paths, servers): "servers": servers, "paths": paths, } - return Spec.from_dict(spec) + return Spec.from_dict(spec, validator=None) @pytest.fixture def finder(self, spec): @@ -151,7 +151,7 @@ def spec(self, info, paths): "info": info, "paths": paths, } - return Spec.from_dict(spec) + return Spec.from_dict(spec, validator=None) class BaseTestOperationServer(BaseTestSpecServer): @@ -171,7 +171,7 @@ def spec(self, info, paths): "info": info, "paths": paths, } - return Spec.from_dict(spec) + return Spec.from_dict(spec, validator=None) class BaseTestServerNotFound: diff --git a/tests/unit/templating/test_responses_finders.py b/tests/unit/templating/test_responses_finders.py index bfcd9af1..a5b62909 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) + return Spec.from_dict(spec, validator=None) @pytest.fixture(scope="class") def finder(self, responses): diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index d0e2018b..507f2bce 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -55,7 +55,7 @@ def test_schema_type_invalid(self, unmarshaller_factory): schema = { "type": "integer", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "test" with pytest.raises(InvalidSchemaFormatValue): @@ -75,7 +75,7 @@ def unmarshal(self, value): "type": "string", "format": "custom", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "test" with pytest.raises(InvalidSchemaFormatValue): @@ -95,7 +95,7 @@ def test_deprecated(self, unmarshaller_factory): "type": "string", "deprecated": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "test" with pytest.warns(DeprecationWarning): @@ -116,7 +116,7 @@ def test_non_string_empty_value(self, schema_type, unmarshaller_factory): schema = { "type": schema_type, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "" with pytest.raises(InvalidSchemaValue): @@ -126,7 +126,7 @@ def test_string_valid(self, unmarshaller_factory): schema = { "type": "string", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "test" result = unmarshaller_factory(spec)(value) @@ -138,7 +138,7 @@ def test_string_format_uuid_valid(self, unmarshaller_factory): "type": "string", "format": "uuid", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = str(uuid.uuid4()) result = unmarshaller_factory(spec)(value) @@ -152,7 +152,7 @@ def test_string_format_uuid_uuid_quirks_invalid( "type": "string", "format": "uuid", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = uuid.uuid4() with pytest.raises(InvalidSchemaValue): @@ -163,7 +163,7 @@ def test_string_format_password(self, unmarshaller_factory): "type": "string", "format": "password", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "password" result = unmarshaller_factory(spec)(value) @@ -174,7 +174,7 @@ def test_string_float_invalid(self, unmarshaller_factory): schema = { "type": "string", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 1.23 with pytest.raises(InvalidSchemaValue): @@ -185,7 +185,7 @@ def test_string_format_date(self, unmarshaller_factory): "type": "string", "format": "date", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2018-01-02" result = unmarshaller_factory(spec)(value) @@ -197,7 +197,7 @@ def test_string_format_datetime_invalid(self, unmarshaller_factory): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2018-01-02T00:00:00" with pytest.raises(InvalidSchemaValue): @@ -208,7 +208,7 @@ def test_string_format_datetime_utc(self, unmarshaller_factory): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2018-01-02T00:00:00Z" result = unmarshaller_factory(spec)(value) @@ -221,7 +221,7 @@ def test_string_format_datetime_tz(self, unmarshaller_factory): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2020-04-01T12:00:00+02:00" result = unmarshaller_factory(spec)(value) @@ -241,7 +241,7 @@ def unmarshal(self, value): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "x" formatter = CustomFormatter() custom_formatters = { @@ -264,7 +264,7 @@ def unmarshal(self, value): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "x" formatter = CustomFormatter() custom_formatters = { @@ -282,7 +282,7 @@ def test_string_format_unknown(self, unmarshaller_factory): "type": "string", "format": unknown_format, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "x" with pytest.raises(FormatterNotFoundError): @@ -294,7 +294,7 @@ def test_string_format_invalid_value(self, unmarshaller_factory): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "x" with pytest.raises( @@ -307,7 +307,7 @@ def test_integer_valid(self, unmarshaller_factory): schema = { "type": "integer", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 123 result = unmarshaller_factory(spec)(value) @@ -318,7 +318,7 @@ def test_integer_string_invalid(self, unmarshaller_factory): schema = { "type": "integer", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "123" with pytest.raises(InvalidSchemaValue): @@ -329,7 +329,7 @@ def test_integer_enum_invalid(self, unmarshaller_factory): "type": "integer", "enum": [1, 2, 3], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "123" with pytest.raises(UnmarshalError): @@ -340,7 +340,7 @@ def test_integer_enum(self, unmarshaller_factory): "type": "integer", "enum": [1, 2, 3], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 2 result = unmarshaller_factory(spec)(value) @@ -352,7 +352,7 @@ def test_integer_enum_string_invalid(self, unmarshaller_factory): "type": "integer", "enum": [1, 2, 3], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2" with pytest.raises(UnmarshalError): @@ -365,7 +365,7 @@ def test_integer_default_nullable(self, unmarshaller_factory): "default": default_value, "nullable": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = None result = unmarshaller_factory(spec)(value) @@ -376,7 +376,7 @@ def test_integer_invalid(self, unmarshaller_factory): schema = { "type": "integer", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "abc" with pytest.raises(InvalidSchemaValue): @@ -389,7 +389,7 @@ def test_array_valid(self, unmarshaller_factory): "type": "integer", }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = [1, 2, 3] result = unmarshaller_factory(spec)(value) @@ -403,7 +403,7 @@ def test_array_null(self, unmarshaller_factory): "type": "integer", }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = None with pytest.raises(InvalidSchemaValue): @@ -417,7 +417,7 @@ def test_array_nullable(self, unmarshaller_factory): }, "nullable": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = None result = unmarshaller_factory(spec)(value) @@ -430,7 +430,7 @@ def test_array_of_string_string_invalid(self, unmarshaller_factory): "type": "string", }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "123" with pytest.raises(InvalidSchemaValue): @@ -443,7 +443,7 @@ def test_array_of_integer_string_invalid(self, unmarshaller_factory): "type": "integer", }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "123" with pytest.raises(InvalidSchemaValue): @@ -453,7 +453,7 @@ def test_boolean_valid(self, unmarshaller_factory): schema = { "type": "boolean", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = True result = unmarshaller_factory(spec)(value) @@ -464,7 +464,7 @@ def test_boolean_string_invalid(self, unmarshaller_factory): schema = { "type": "boolean", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "True" with pytest.raises(InvalidSchemaValue): @@ -474,7 +474,7 @@ def test_number_valid(self, unmarshaller_factory): schema = { "type": "number", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 1.23 result = unmarshaller_factory(spec)(value) @@ -485,7 +485,7 @@ def test_number_string_invalid(self, unmarshaller_factory): schema = { "type": "number", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "1.23" with pytest.raises(InvalidSchemaValue): @@ -495,7 +495,7 @@ def test_number_int(self, unmarshaller_factory): schema = { "type": "number", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 1 result = unmarshaller_factory(spec)(value) @@ -506,7 +506,7 @@ def test_number_float(self, unmarshaller_factory): schema = { "type": "number", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 1.2 result = unmarshaller_factory(spec)(value) @@ -518,7 +518,7 @@ def test_number_format_float(self, unmarshaller_factory): "type": "number", "format": "float", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 1.2 result = unmarshaller_factory(spec)(value) @@ -529,7 +529,7 @@ def test_number_format_double(self, unmarshaller_factory): "type": "number", "format": "double", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = 1.2 result = unmarshaller_factory(spec)(value) @@ -545,7 +545,7 @@ def test_object_nullable(self, unmarshaller_factory): } }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = {"foo": None} result = unmarshaller_factory(spec)(value) @@ -567,7 +567,7 @@ def test_schema_any_one_of(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)(["hello"]) == ["hello"] def test_schema_any_any_of(self, unmarshaller_factory): @@ -584,7 +584,7 @@ def test_schema_any_any_of(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)(["hello"]) == ["hello"] def test_schema_object_any_of(self, unmarshaller_factory): @@ -603,7 +603,7 @@ def test_schema_object_any_of(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = unmarshaller_factory(spec)({"someint": 1}) assert result == { @@ -626,7 +626,7 @@ def test_schema_object_any_of_invalid(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(UnmarshalError): unmarshaller_factory(spec)({"someint": "1"}) @@ -659,7 +659,7 @@ def test_schema_object_one_of_default(self, unmarshaller_factory): }, }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)({"someint": 1}) == { "someint": 1, "somestr": "defaultstring", @@ -688,7 +688,7 @@ def test_schema_object_any_of_default(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)({"someint": "1"}) == { "someint": "1", "somestr": "defaultstring", @@ -718,7 +718,7 @@ def test_schema_object_all_of_default(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)({}) == { "someint": 1, "somestr": "defaultstring", @@ -735,7 +735,7 @@ def test_schema_any_all_of(self, unmarshaller_factory): } ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)(["hello"]) == ["hello"] @pytest.mark.parametrize( @@ -786,7 +786,7 @@ def test_schema_any_all_of_invalid_properties( ], "additionalProperties": False, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): unmarshaller_factory(spec)(value) @@ -801,7 +801,7 @@ def test_schema_any_any_of_any(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2018-01-02" result = unmarshaller_factory(spec)(value) @@ -818,7 +818,7 @@ def test_schema_any_all_of_any(self, unmarshaller_factory): }, ], } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "2018-01-02" result = unmarshaller_factory(spec)(value) @@ -827,7 +827,7 @@ def test_schema_any_all_of_any(self, unmarshaller_factory): def test_schema_any(self, unmarshaller_factory): schema = {} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) assert unmarshaller_factory(spec)("string") == "string" @pytest.mark.parametrize( @@ -846,7 +846,7 @@ def test_schema_free_form_object( "type": "object", "additionalProperties": additional_properties, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = unmarshaller_factory(spec)(value) @@ -863,7 +863,7 @@ def test_read_only_properties(self, unmarshaller_factory): } }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) # readOnly properties may be admitted in a Response context result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)( @@ -885,7 +885,7 @@ def test_read_only_properties_invalid(self, unmarshaller_factory): } }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) # readOnly properties are not admitted on a Request context with pytest.raises(InvalidSchemaValue): @@ -904,7 +904,7 @@ def test_write_only_properties(self, unmarshaller_factory): } }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) # readOnly properties may be admitted in a Response context result = unmarshaller_factory(spec, context=UnmarshalContext.REQUEST)( @@ -926,7 +926,7 @@ def test_write_only_properties_invalid(self, unmarshaller_factory): } }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) # readOnly properties are not admitted on a Request context with pytest.raises(InvalidSchemaValue): @@ -936,7 +936,7 @@ def test_write_only_properties_invalid(self, unmarshaller_factory): def test_additional_properties_list(self, unmarshaller_factory): schema = {"type": "object"} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)( {"user_ids": [1, 2, 3, 4]} @@ -949,7 +949,7 @@ def test_additional_properties_list(self, unmarshaller_factory): @pytest.mark.xfail(message="None and NOTSET should be distinguished") def test_null_not_supported(self, unmarshaller_factory): schema = {"type": "null"} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): unmarshaller_factory(spec)(None) @@ -969,7 +969,7 @@ def test_nultiple_types_not_supported( self, unmarshaller_factory, types, value ): schema = {"type": types} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(TypeError): unmarshaller_factory(spec)(value) @@ -982,7 +982,7 @@ def unmarshaller_factory(self, schema_unmarshaller_factory): def test_null(self, unmarshaller_factory): schema = {"type": "null"} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = unmarshaller_factory(spec)(None) @@ -991,7 +991,7 @@ def test_null(self, unmarshaller_factory): @pytest.mark.parametrize("value", ["string", 2, 3.14, True, [1, 2], {}]) def test_null_invalid(self, unmarshaller_factory, value): schema = {"type": "null"} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): unmarshaller_factory(spec)(value) @@ -1009,7 +1009,7 @@ def test_null_invalid(self, unmarshaller_factory, value): ) def test_nultiple_types(self, unmarshaller_factory, types, value): schema = {"type": types} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = unmarshaller_factory(spec)(value) @@ -1028,7 +1028,7 @@ def test_nultiple_types(self, unmarshaller_factory, types, value): ) def test_nultiple_types_invalid(self, unmarshaller_factory, types, value): schema = {"type": types} - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): unmarshaller_factory(spec)(value) diff --git a/tests/unit/unmarshalling/test_validate.py b/tests/unit/unmarshalling/test_validate.py index 9ad18fa5..22b49dc8 100644 --- a/tests/unit/unmarshalling/test_validate.py +++ b/tests/unit/unmarshalling/test_validate.py @@ -35,7 +35,7 @@ def test_null(self, schema_type, validator_factory): schema = { "type": schema_type, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = None with pytest.raises(InvalidSchemaValue): @@ -56,7 +56,7 @@ def test_nullable(self, schema_type, validator_factory): "type": schema_type, "nullable": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = None result = validator_factory(spec).validate(value) @@ -69,7 +69,7 @@ def test_string_format_custom_missing(self, validator_factory): "type": "string", "format": custom_format, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) value = "x" with pytest.raises(FormatterNotFoundError): @@ -80,7 +80,7 @@ def test_boolean(self, value, validator_factory): schema = { "type": "boolean", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -91,7 +91,7 @@ def test_boolean_invalid(self, value, validator_factory): schema = { "type": "boolean", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -101,7 +101,7 @@ def test_array_no_schema(self, value, validator_factory): schema = { "type": "array", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -114,7 +114,7 @@ def test_array(self, value, validator_factory): "type": "integer", }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -125,7 +125,7 @@ def test_array_invalid(self, value, validator_factory): schema = { "type": "array", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -135,7 +135,7 @@ def test_integer(self, value, validator_factory): schema = { "type": "integer", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -146,7 +146,7 @@ def test_integer_invalid(self, value, validator_factory): schema = { "type": "integer", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -157,7 +157,7 @@ def test_integer_minimum_invalid(self, value, validator_factory): "type": "integer", "minimum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -168,7 +168,7 @@ def test_integer_minimum(self, value, validator_factory): "type": "integer", "minimum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -180,7 +180,7 @@ def test_integer_maximum_invalid(self, value, validator_factory): "type": "integer", "maximum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -191,7 +191,7 @@ def test_integer_maximum(self, value, validator_factory): "type": "integer", "maximum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -203,7 +203,7 @@ def test_integer_multiple_of_invalid(self, value, validator_factory): "type": "integer", "multipleOf": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -214,7 +214,7 @@ def test_integer_multiple_of(self, value, validator_factory): "type": "integer", "multipleOf": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -225,7 +225,7 @@ def test_number(self, value, validator_factory): schema = { "type": "number", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -236,7 +236,7 @@ def test_number_invalid(self, value, validator_factory): schema = { "type": "number", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -247,7 +247,7 @@ def test_number_minimum_invalid(self, value, validator_factory): "type": "number", "minimum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -258,7 +258,7 @@ def test_number_minimum(self, value, validator_factory): "type": "number", "minimum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -271,7 +271,7 @@ def test_number_exclusive_minimum_invalid(self, value, validator_factory): "minimum": 3, "exclusiveMinimum": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -283,7 +283,7 @@ def test_number_exclusive_minimum(self, value, validator_factory): "minimum": 3, "exclusiveMinimum": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -295,7 +295,7 @@ def test_number_maximum_invalid(self, value, validator_factory): "type": "number", "maximum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -306,7 +306,7 @@ def test_number_maximum(self, value, validator_factory): "type": "number", "maximum": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -319,7 +319,7 @@ def test_number_exclusive_maximum_invalid(self, value, validator_factory): "maximum": 3, "exclusiveMaximum": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -331,7 +331,7 @@ def test_number_exclusive_maximum(self, value, validator_factory): "maximum": 3, "exclusiveMaximum": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -343,7 +343,7 @@ def test_number_multiple_of_invalid(self, value, validator_factory): "type": "number", "multipleOf": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -354,7 +354,7 @@ def test_number_multiple_of(self, value, validator_factory): "type": "number", "multipleOf": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -365,7 +365,7 @@ def test_string(self, value, validator_factory): schema = { "type": "string", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -376,7 +376,7 @@ def test_string_invalid(self, value, validator_factory): schema = { "type": "string", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -398,7 +398,7 @@ def test_string_format_date_invalid(self, value, validator_factory): "type": "string", "format": "date", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -415,7 +415,7 @@ def test_string_format_date(self, value, validator_factory): "type": "string", "format": "date", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -432,7 +432,7 @@ def test_string_format_uuid(self, value, validator_factory): "type": "string", "format": "uuid", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -456,7 +456,7 @@ def test_string_format_uuid_invalid(self, value, validator_factory): "type": "string", "format": "uuid", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -478,7 +478,7 @@ def test_string_format_datetime_invalid(self, value, validator_factory): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -503,7 +503,7 @@ def test_string_format_datetime_strict_rfc3339( "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -528,7 +528,7 @@ def test_string_format_datetime_isodate(self, value, validator_factory): "type": "string", "format": "date-time", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -551,7 +551,7 @@ def test_string_format_binary_invalid(self, value, validator_factory): "type": "string", "format": "binary", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -568,7 +568,7 @@ def test_string_format_binary(self, value, validator_factory): "type": "string", "format": "binary", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -586,7 +586,7 @@ def test_string_format_byte(self, value, validator_factory): "type": "string", "format": "byte", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -605,7 +605,7 @@ def test_string_format_byte_invalid(self, value, validator_factory): "type": "string", "format": "byte", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -625,7 +625,7 @@ def test_string_format_unknown(self, value, validator_factory): "type": "string", "format": unknown_format, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(FormatterNotFoundError): validator_factory(spec).validate(value) @@ -636,7 +636,7 @@ def test_string_min_length_invalid(self, value, validator_factory): "type": "string", "minLength": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -647,7 +647,7 @@ def test_string_min_length(self, value, validator_factory): "type": "string", "minLength": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -664,7 +664,7 @@ def test_string_max_length_invalid_schema(self, value, validator_factory): "type": "string", "maxLength": -1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -675,7 +675,7 @@ def test_string_max_length_invalid(self, value, validator_factory): "type": "string", "maxLength": 1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -686,7 +686,7 @@ def test_string_max_length(self, value, validator_factory): "type": "string", "maxLength": 1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -698,7 +698,7 @@ def test_string_pattern_invalid(self, value, validator_factory): "type": "string", "pattern": "baz", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -709,7 +709,7 @@ def test_string_pattern(self, value, validator_factory): "type": "string", "pattern": "bar", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -720,7 +720,7 @@ def test_object_not_an_object(self, value, validator_factory): schema = { "type": "object", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -744,7 +744,7 @@ def test_object_multiple_one_of(self, value, validator_factory): "type": "object", "oneOf": one_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -768,7 +768,7 @@ def test_object_different_type_one_of(self, value, validator_factory): "type": "object", "oneOf": one_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -808,7 +808,7 @@ def test_object_no_one_of(self, value, validator_factory): "type": "object", "oneOf": one_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -857,7 +857,7 @@ def test_unambiguous_one_of(self, value, validator_factory): "type": "object", "oneOf": one_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -882,7 +882,7 @@ def test_object_multiple_any_of(self, value, validator_factory): "type": "object", "anyOf": any_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -900,7 +900,7 @@ def test_object_different_type_any_of(self, value, validator_factory): "type": "object", "anyOf": any_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -936,7 +936,7 @@ def test_object_no_any_of(self, value, validator_factory): "type": "object", "anyOf": any_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -983,7 +983,7 @@ def test_unambiguous_any_of(self, value, validator_factory): "type": "object", "anyOf": any_of, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1000,7 +1000,7 @@ def test_object_default_property(self, value, validator_factory): "type": "object", "default": "value1", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1019,7 +1019,7 @@ def test_object_min_properties_invalid_schema( "type": "object", "minProperties": 2, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -1038,7 +1038,7 @@ def test_object_min_properties_invalid(self, value, validator_factory): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "minProperties": 4, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -1057,7 +1057,7 @@ def test_object_min_properties(self, value, validator_factory): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "minProperties": 1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) assert result is None @@ -1075,7 +1075,7 @@ def test_object_max_properties_invalid_schema( "type": "object", "maxProperties": -1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -1094,7 +1094,7 @@ def test_object_max_properties_invalid(self, value, validator_factory): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "maxProperties": 0, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -1113,7 +1113,7 @@ def test_object_max_properties(self, value, validator_factory): "properties": {k: {"type": "number"} for k in ["a", "b", "c"]}, "maxProperties": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1129,7 +1129,7 @@ def test_object_additional_properties(self, value, validator_factory): schema = { "type": "object", } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1148,7 +1148,7 @@ def test_object_additional_properties_false( "type": "object", "additionalProperties": False, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -1169,7 +1169,7 @@ def test_object_additional_properties_object( "type": "object", "additionalProperties": additional_properties, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1184,7 +1184,7 @@ def test_list_min_items_invalid(self, value, validator_factory): }, "minItems": 3, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(Exception): validator_factory(spec).validate(value) @@ -1198,7 +1198,7 @@ def test_list_min_items(self, value, validator_factory): }, "minItems": 0, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1218,7 +1218,7 @@ def test_list_max_items_invalid_schema(self, value, validator_factory): }, "maxItems": -1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(InvalidSchemaValue): validator_factory(spec).validate(value) @@ -1232,7 +1232,7 @@ def test_list_max_items_invalid(self, value, validator_factory): }, "maxItems": 1, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(Exception): validator_factory(spec).validate(value) @@ -1246,7 +1246,7 @@ def test_list_unique_items_invalid(self, value, validator_factory): }, "uniqueItems": True, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(Exception): validator_factory(spec).validate(value) @@ -1278,7 +1278,7 @@ def test_object_with_properties(self, value, validator_factory): }, }, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) result = validator_factory(spec).validate(value) @@ -1319,7 +1319,7 @@ def test_object_with_invalid_properties(self, value, validator_factory): }, "additionalProperties": False, } - spec = Spec.from_dict(schema) + spec = Spec.from_dict(schema, validator=None) with pytest.raises(Exception): validator_factory(spec).validate(value)