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

Resolve external references in custom schemas #738

Conversation

eslavich
Copy link
Contributor

@eslavich eslavich commented Jan 24, 2020

Previously, external references in custom schemas were not being resolved (see #683). This was clearly deliberate, though I can't think of a reason why that would be the desired behavior. This PR changes the custom schema behavior to resolve external references, and fixes an issue in the tests that prevented the example custom schema from resolving correctly.

Resolves #683

@codecov
Copy link

codecov bot commented Jan 24, 2020

Codecov Report

Merging #738 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #738      +/-   ##
==========================================
+ Coverage    93.3%   93.31%   +<.01%     
==========================================
  Files          39       39              
  Lines        4391     4382       -9     
==========================================
- Hits         4097     4089       -8     
+ Misses        294      293       -1
Impacted Files Coverage Δ
asdf/asdf.py 93.84% <100%> (-0.02%) ⬇️
asdf/schema.py 93.41% <100%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 385f7c2...06b4109. Read the comment docs.

@eslavich eslavich added this to the 2.6 milestone Jan 24, 2020

if custom_schema is not None:
self._custom_schema = schema.load_custom_schema(custom_schema)
schema.check_schema(self._custom_schema)
self._custom_schema = schema.load_schema(custom_schema, self.resolver, True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved after the call to self._process_extensions so that we could use our AsdfFile's resolver when loading the custom schema.

@@ -1,9 +1,7 @@
%YAML 1.1
---
$schema: "http://stsci.edu/schemas/yaml-schema/draft-01"
id: "http://stsci.edu/schemas/asdf/core/asdf-1.1.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-using the core schema id causes problems when resolving external references. I don't think it's a good idea anyway, since the ids are meant to be globally unique.

custom = load_schema(url, resolve_local_refs=True)
core = load_schema(AsdfObject.yaml_tag)

def update(d, u):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's actually necessary to merge the core schema with the custom schema, since we already check against the core schema in a first validation pass.

@eslavich eslavich force-pushed the AL-216-resolve-external-references-in-custom-schema branch from 423d033 to a6d817a Compare January 25, 2020 00:54
Copy link
Contributor

@nden nden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@jdavies-st jdavies-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Just a couple niggles below that should not prevent from merging.

asdf/tests/test_schema.py Outdated Show resolved Hide resolved
asdf/tests/test_schema.py Outdated Show resolved Hide resolved
asdf/tests/test_schema.py Outdated Show resolved Hide resolved
@eslavich eslavich merged commit 7f5bc02 into asdf-format:master Jan 27, 2020
@eslavich eslavich deleted the AL-216-resolve-external-references-in-custom-schema branch January 27, 2020 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

custom_schema arg doesn't use correct resolver or extensions
3 participants