Skip to content

Commit d715573

Browse files
authored
Merge pull request #949 from EpicWink/fix-unevaluated
Only validate unevaluated properties/items on applicable types
2 parents 63d0af6 + 731be4f commit d715573

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

jsonschema/_validators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ def if_(validator, if_schema, instance, schema):
418418

419419

420420
def unevaluatedItems(validator, unevaluatedItems, instance, schema):
421+
if not validator.is_type(instance, "array"):
422+
return
421423
evaluated_item_indexes = find_evaluated_item_indexes_by_schema(
422424
validator, instance, schema,
423425
)
@@ -431,6 +433,8 @@ def unevaluatedItems(validator, unevaluatedItems, instance, schema):
431433

432434

433435
def unevaluatedProperties(validator, unevaluatedProperties, instance, schema):
436+
if not validator.is_type(instance, "object"):
437+
return
434438
evaluated_property_keys = find_evaluated_property_keys_by_schema(
435439
validator, instance, schema,
436440
)

jsonschema/tests/test_jsonschema_test_suite.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,6 @@ def leap_second(test):
346346
message="unevaluatedItems is different in 2019-09 (needs work).",
347347
subject="unevaluatedItems",
348348
)(test)
349-
or skip(
350-
message=bug(949),
351-
subject="unevaluatedProperties",
352-
case_description="non-object instances are valid",
353-
)(test)
354349
or skip(
355350
message="dynamicRef support isn't working yet.",
356351
subject="recursiveRef",
@@ -416,16 +411,6 @@ def leap_second(test):
416411
message="Vocabulary support is not yet present.",
417412
subject="vocabulary",
418413
)(test)
419-
or skip(
420-
message=bug(949),
421-
subject="unevaluatedItems",
422-
case_description="non-array instances are valid",
423-
)(test)
424-
or skip(
425-
message=bug(949),
426-
subject="unevaluatedProperties",
427-
case_description="non-object instances are valid",
428-
)(test)
429414
or skip(
430415
message=bug(),
431416
subject="ref",

jsonschema/tests/test_validators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ def test_unevaluated_items(self):
597597
"Unevaluated items are not allowed ('bar', 'foo' were unexpected)",
598598
)
599599

600+
def test_unevaluated_items_on_invalid_type(self):
601+
schema = {"type": "array", "unevaluatedItems": False}
602+
message = self.message_for(instance="foo", schema=schema)
603+
self.assertEqual(message, "'foo' is not of type 'array'")
604+
600605
def test_unevaluated_properties(self):
601606
schema = {"type": "object", "unevaluatedProperties": False}
602607
message = self.message_for(
@@ -612,6 +617,11 @@ def test_unevaluated_properties(self):
612617
"('bar', 'foo' were unexpected)",
613618
)
614619

620+
def test_unevaluated_properties_on_invalid_type(self):
621+
schema = {"type": "object", "unevaluatedProperties": False}
622+
message = self.message_for(instance="foo", schema=schema)
623+
self.assertEqual(message, "'foo' is not of type 'object'")
624+
615625

616626
class TestValidationErrorDetails(TestCase):
617627
# TODO: These really need unit tests for each individual validator, rather

0 commit comments

Comments
 (0)