diff --git a/projects/yamlschema/test_yamlschema.py b/projects/yamlschema/test_yamlschema.py index 2e50678..f03834e 100644 --- a/projects/yamlschema/test_yamlschema.py +++ b/projects/yamlschema/test_yamlschema.py @@ -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 diff --git a/projects/yamlschema/yamlschema.py b/projects/yamlschema/yamlschema.py index 0cb7c54..1f023b5 100644 --- a/projects/yamlschema/yamlschema.py +++ b/projects/yamlschema/yamlschema.py @@ -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