summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-26 09:48:32 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-26 10:04:54 +0100
commit288620719b2c395f554cff9f56834107de11d4b3 (patch)
tree656e2dee59fe2af7f84cc9baf35c746131ab48f9
parent996437f0693adf66ac6d24df7770057fc0fd9b15 (diff)
downloadjsonschema-288620719b2c395f554cff9f56834107de11d4b3.tar.gz
Add test cases for error details hidden behind a $ref
These indeed can be improved, as mentioned in https://github.com/Julian/jsonschema/pull/817#issuecomment-881550313 but it's a bit less clear exactly how yet -- rather than putting $ref in the schema path, instead using relative_schema_path to only refer to the schema post-$ref lookup is a bit more consistent with the current norms, wherein what's in schema_path should be lookup-able via indexing. But for now, they're distinguishable via .schema, which shows only the $ref'ed schema for the second error.
-rw-r--r--jsonschema/tests/test_validators.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index 915758f..30f07af 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -1325,6 +1325,68 @@ class TestValidationErrorDetails(TestCase):
),
)
+ def test_ref_sibling(self):
+ schema = {
+ "$defs": {"foo": {"required": ["bar"]}},
+ "properties": {
+ "aprop": {
+ "$ref": "#/$defs/foo",
+ "required": ["baz"]
+ },
+ },
+ }
+
+ validator = validators.Draft202012Validator(schema)
+ e1, e2 = validator.iter_errors({"aprop": {}})
+ self.assertEqual(
+ (
+ e1.message,
+ e1.validator,
+ e1.validator_value,
+ e1.instance,
+ e1.absolute_path,
+ e1.schema,
+ e1.schema_path,
+ e1.relative_schema_path,
+ e1.json_path,
+ ),
+ (
+ "'bar' is a required property",
+ "required",
+ ["bar"],
+ {},
+ deque(["aprop"]),
+ {"required": ["bar"]},
+ deque(["properties", "aprop", "required"]),
+ deque(["properties", "aprop", "required"]),
+ "$.aprop",
+ ),
+ )
+ self.assertEqual(
+ (
+ e2.message,
+ e2.validator,
+ e2.validator_value,
+ e2.instance,
+ e2.absolute_path,
+ e2.schema,
+ e2.schema_path,
+ e2.relative_schema_path,
+ e2.json_path,
+ ),
+ (
+ "'baz' is a required property",
+ "required",
+ ["baz"],
+ {},
+ deque(["aprop"]),
+ {"$ref": "#/$defs/foo", "required": ["baz"]},
+ deque(["properties", "aprop", "required"]),
+ deque(["properties", "aprop", "required"]),
+ "$.aprop",
+ ),
+ )
+
class MetaSchemaTestsMixin(object):
# TODO: These all belong upstream