summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2019-01-11 14:58:40 -0500
committerJulian Berman <Julian@GrayVines.com>2019-01-11 15:08:46 -0500
commit21af2e4723715aea92f2e6a89e7c83e81bfd2c44 (patch)
tree805eabae77c12b8524c87baf89c8d38829e2ea56
parent6466d070ad579e8cfea98bc2756b48bb08d2b20c (diff)
downloadjsonschema-21af2e4723715aea92f2e6a89e7c83e81bfd2c44.tar.gz
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...
-rw-r--r--jsonschema/_validators.py1
-rw-r--r--jsonschema/tests/test_validators.py14
2 files changed, 14 insertions, 1 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py
index 507305e..9b8cc17 100644
--- a/jsonschema/_validators.py
+++ b/jsonschema/_validators.py
@@ -26,7 +26,6 @@ def propertyNames(validator, propertyNames, instance, schema):
for error in validator.descend(
instance=property,
schema=propertyNames,
- path=property, # FIXME: path?
):
yield error
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index 7a91f34..466ccd6 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -881,6 +881,20 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.validator, "type")
self.assertEqual(e2.validator, "minimum")
+ def test_propertyNames(self):
+ instance = {"foo": 12}
+ schema = {"propertyNames": {"not": {"const": "foo"}}}
+
+ validator = validators.Draft7Validator(schema)
+ error, = validator.iter_errors(instance)
+
+ self.assertEqual(error.validator, "not")
+ self.assertEqual(
+ error.message,
+ "%r is not allowed for %r" % ({"const": "foo"}, "foo"),
+ )
+ self.assertEqual(error.path, deque([]))
+
class MetaSchemaTestsMixin(object):
# TODO: These all belong upstream