Skip to content

Commit 21af2e4

Browse files
committed
Fix the error properties for propertyNames.
Note that propertyNames is another example (like #119) of something that needs an additional way to say it has errored on a *key* within the instance. So, that's still missing, but path is not the right thing, same as in the earlier instances. It's also becoming somewhat clear that compound validators should possibly grow a way to become lazy...
1 parent 6466d07 commit 21af2e4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

jsonschema/_validators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def propertyNames(validator, propertyNames, instance, schema):
2626
for error in validator.descend(
2727
instance=property,
2828
schema=propertyNames,
29-
path=property, # FIXME: path?
3029
):
3130
yield error
3231

jsonschema/tests/test_validators.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,20 @@ def test_additionalItems_with_items(self):
881881
self.assertEqual(e1.validator, "type")
882882
self.assertEqual(e2.validator, "minimum")
883883

884+
def test_propertyNames(self):
885+
instance = {"foo": 12}
886+
schema = {"propertyNames": {"not": {"const": "foo"}}}
887+
888+
validator = validators.Draft7Validator(schema)
889+
error, = validator.iter_errors(instance)
890+
891+
self.assertEqual(error.validator, "not")
892+
self.assertEqual(
893+
error.message,
894+
"%r is not allowed for %r" % ({"const": "foo"}, "foo"),
895+
)
896+
self.assertEqual(error.path, deque([]))
897+
884898

885899
class MetaSchemaTestsMixin(object):
886900
# TODO: These all belong upstream

0 commit comments

Comments
 (0)