Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref_resolver index makes entries for import: and include: #655

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions schema_salad/ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def resolve_ref(
lref = ref
obj = None # type: Optional[CommentedMap]
resolved_obj = None # type: ResolveType
imp = False
inc = False
mixin = None # type: Optional[MutableMapping[str, str]]

Expand All @@ -426,6 +427,7 @@ def resolve_ref(
if "$import" in obj:
if len(obj) == 1:
lref = obj["$import"]
imp = True
obj = None
else:
raise ValidationException(
Expand Down Expand Up @@ -506,6 +508,8 @@ def resolve_ref(

# "$include" directive means load raw text
if inc:
# Make a note in the index that this was an included string
self.idx["include:" + url] = url
return self.fetch_text(url), CommentedMap()

doc = None
Expand All @@ -528,6 +532,10 @@ def resolve_ref(
doc_url, inject_ids=(not mixin), content_types=content_types
)

if imp:
# Make a note in the index that this was an imported fragment
self.idx["import:" + url] = url

# Recursively expand urls and resolve directives
if bool(mixin):
doc = copy.deepcopy(doc)
Expand Down
4 changes: 4 additions & 0 deletions schema_salad/tests/test_ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def test_import_list() -> None:

assert {"foo": ["bar", "baz"]} == ra

importfile = "import:%slist.json" % basedir

assert importfile in loader.idx


def test_fetch_inject_id() -> None:
path = get_data("tests/inject-id1.yml")
Expand Down