Skip to content

Commit

Permalink
Add test cases for error details hidden behind a $ref
Browse files Browse the repository at this point in the history
These indeed can be improved, as mentioned in
#817 (comment)
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.
  • Loading branch information
Julian committed Aug 26, 2021
1 parent 996437f commit 2886207
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions jsonschema/tests/test_validators.py
Expand Up @@ -1325,6 +1325,68 @@ def test_contains_none(self):
),
)

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
Expand Down

0 comments on commit 2886207

Please sign in to comment.