From 71bafd7ae398184986b3115b66cc803ba4247066 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Mon, 12 Jun 2023 11:06:32 +0100 Subject: [PATCH] drop oas30 read write properties --- openapi_schema_validator/validators.py | 38 ------------ tests/integration/test_validators.py | 84 -------------------------- 2 files changed, 122 deletions(-) diff --git a/openapi_schema_validator/validators.py b/openapi_schema_validator/validators.py index 5d71543..e8c4bd3 100644 --- a/openapi_schema_validator/validators.py +++ b/openapi_schema_validator/validators.py @@ -97,41 +97,3 @@ type_checker=oas31_type_checker, format_checker=oas_format.oas31_format_checker, ) - - -def _patch_validator_with_read_write_context(cls: Type[Validator]) -> None: - """Adds read/write context to jsonschema validator class""" - # subclassing validator classes is not intended to - # be part of their public API and will raise error - # See https://github.com/python-openapi/openapi-schema-validator/issues/48 - original_init = cls.__init__ - original_evolve = cls.evolve - - def __init__(self: Validator, *args: Any, **kwargs: Any) -> None: - self.read = kwargs.pop("read", None) - if self.read is not None: - warnings.warn( - "read property is deprecated. " - "Use OAS30ReadValidator instead.", - DeprecationWarning, - ) - self.write = kwargs.pop("write", None) - if self.write is not None: - warnings.warn( - "write property is deprecated. " - "Use OAS30WriteValidator instead.", - DeprecationWarning, - ) - original_init(self, *args, **kwargs) - - def evolve(self: Validator, **changes: Any) -> Validator: - validator = original_evolve(self, **changes) - validator.read = self.read - validator.write = self.write - return validator - - cls.__init__ = __init__ - cls.evolve = evolve - - -_patch_validator_with_read_write_context(OAS30Validator) diff --git a/tests/integration/test_validators.py b/tests/integration/test_validators.py index 9fc85a1..73daf9c 100644 --- a/tests/integration/test_validators.py +++ b/tests/integration/test_validators.py @@ -284,90 +284,6 @@ def test_required(self, validator_class): validator.validate({"another_prop": "bla"}) assert validator.validate({"some_prop": "hello"}) is None - def test_read_only(self, validator_class): - schema = { - "type": "object", - "properties": {"some_prop": {"type": "string", "readOnly": True}}, - } - - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, write=True - ) - with pytest.raises( - ValidationError, - match="Tried to write read-only property with hello", - ): - validator.validate({"some_prop": "hello"}) - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, read=True - ) - assert validator.validate({"some_prop": "hello"}) is None - - def test_write_only(self, validator_class): - schema = { - "type": "object", - "properties": {"some_prop": {"type": "string", "writeOnly": True}}, - } - - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, read=True - ) - with pytest.raises( - ValidationError, - match="Tried to read write-only property with hello", - ): - validator.validate({"some_prop": "hello"}) - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, write=True - ) - assert validator.validate({"some_prop": "hello"}) is None - - def test_required_read_only(self, validator_class): - schema = { - "type": "object", - "properties": {"some_prop": {"type": "string", "readOnly": True}}, - "required": ["some_prop"], - } - - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, read=True - ) - with pytest.raises( - ValidationError, match="'some_prop' is a required property" - ): - validator.validate({"another_prop": "hello"}) - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, write=True - ) - assert validator.validate({"another_prop": "hello"}) is None - - def test_required_write_only(self, validator_class): - schema = { - "type": "object", - "properties": {"some_prop": {"type": "string", "writeOnly": True}}, - "required": ["some_prop"], - } - - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, write=True - ) - with pytest.raises( - ValidationError, match="'some_prop' is a required property" - ): - validator.validate({"another_prop": "hello"}) - with pytest.warns(DeprecationWarning): - validator = validator_class( - schema, format_checker=oas30_format_checker, read=True - ) - assert validator.validate({"another_prop": "hello"}) is None - def test_oneof_required(self, validator_class): instance = { "n3IwfId": "string", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy