Get the $ref support working

This commit is contained in:
Reid 'arrdem' McKenzie 2021-05-17 13:56:12 -06:00
parent ea076fb025
commit 977df2c008
2 changed files with 20 additions and 1 deletions

View file

@ -98,3 +98,22 @@ def test_lint_document_ok(schema, obj):
) )
def test_lint_document_fails(msg, schema, obj): def test_lint_document_fails(msg, schema, obj):
assert list(lint_buffer(schema, obj)), msg assert list(lint_buffer(schema, obj)), msg
@pytest.mark.parametrize("msg, schema, obj", [
("Basic usage of $ref",
{"$ref": "#/definitions/Foo",
"definitions": {
"Foo": {"type": "string"},
}},
"---\nfoo"),
("Use of nested references",
{"$ref": "#/definitions/Foos",
"definitions": {
"Foos": {"type": "array", "items": {"$ref": "#/definitions/Foo"}},
"Foo": {"type": "string"},
}},
"---\n- foo\n- bar\n- baz"),
])
def test_ref_references(msg, schema, obj):
assert not list(lint_buffer(schema, obj)), msg

View file

@ -53,7 +53,7 @@ class YamlLinter(object):
path = ref.lstrip("#/").split("/") path = ref.lstrip("#/").split("/")
schema = self._schema schema = self._schema
for e in path: for e in path:
if not (schema := path.get(e)): if not (schema := schema.get(e)):
raise ValueError(f"Unable to dereference {ref}") raise ValueError(f"Unable to dereference {ref}")
return schema return schema