diff --git a/openapi_schema_validator/_keywords.py b/openapi_schema_validator/_keywords.py index 8396418..6f8e097 100644 --- a/openapi_schema_validator/_keywords.py +++ b/openapi_schema_validator/_keywords.py @@ -241,6 +241,8 @@ def write_readOnly( instance: Any, schema: Mapping[str, Any], ) -> Iterator[ValidationError]: + if not ro: + return yield ValidationError(f"Tried to write read-only property with {instance}") @@ -250,6 +252,8 @@ def read_writeOnly( instance: Any, schema: Mapping[str, Any], ) -> Iterator[ValidationError]: + if not wo: + return yield ValidationError(f"Tried to read write-only property with {instance}") diff --git a/tests/integration/test_validators.py b/tests/integration/test_validators.py index 89e9893..24f721a 100644 --- a/tests/integration/test_validators.py +++ b/tests/integration/test_validators.py @@ -670,6 +670,32 @@ def test_required_write_only(self): ) assert validator.validate({"another_prop": "hello"}) is None + def test_read_only_false(self): + schema = { + "type": "object", + "properties": {"some_prop": {"type": "string", "readOnly": False}}, + } + + validator = OAS30WriteValidator( + schema, + format_checker=oas30_format_checker, + ) + assert validator.validate({"some_prop": "hello"}) is None + + def test_write_only_false(self): + schema = { + "type": "object", + "properties": { + "some_prop": {"type": "string", "writeOnly": False} + }, + } + + validator = OAS30ReadValidator( + schema, + format_checker=oas30_format_checker, + ) + assert validator.validate({"some_prop": "hello"}) is None + class TestOAS31ValidatorFormatChecker: @pytest.fixture