Get the $ref support working
This commit is contained in:
parent
ea076fb025
commit
977df2c008
2 changed files with 20 additions and 1 deletions
|
@ -98,3 +98,22 @@ def test_lint_document_ok(schema, obj):
|
|||
)
|
||||
def test_lint_document_fails(msg, schema, obj):
|
||||
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
|
||||
|
|
|
@ -53,7 +53,7 @@ class YamlLinter(object):
|
|||
path = ref.lstrip("#/").split("/")
|
||||
schema = self._schema
|
||||
for e in path:
|
||||
if not (schema := path.get(e)):
|
||||
if not (schema := schema.get(e)):
|
||||
raise ValueError(f"Unable to dereference {ref}")
|
||||
|
||||
return schema
|
||||
|
|
Loading…
Reference in a new issue