From 977df2c0088062b5be81e54c7a94f7c22dd0b1b9 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Mon, 17 May 2021 13:56:12 -0600 Subject: [PATCH] Get the $ref support working --- projects/yamlschema/test_yamlschema.py | 19 +++++++++++++++++++ projects/yamlschema/yamlschema.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) 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