Skip to content

drop oas30 read write properties #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions openapi_schema_validator/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
84 changes: 0 additions & 84 deletions tests/integration/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down