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

Additional/alternative support for complex references #85

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

handrews
Copy link
Contributor

@handrews handrews commented Mar 22, 2023

The combination of this PR and PR #83 mostly fixes #76, although one use case still requires PR #82. This PR and #83 require more work on the part of the caller to configure sources, and require that the relationship between source file names or URLs and the "$id" URIs, such as embedded subschema "$id" URIs, be known in advance.

This PR adds a RewritingSourceMixin class, which allows constructing sources that rewrite the URIs requested so that the URI structure and storage layout can have a more complex relationship.

This particularly facilitates references to schema resources embedded in bundles, or references to URI components that use characters not allowed in filesystems, or a unified URI namespace that is distributed across multiple repositories in a test environment.

The RewritingLocalSource and RewritingRemoteSource simply add the new functionality to the two existing sources. The relevance of PR #83 is that it enables arbitrary rewriting, instead of restricting the rewriting only to valid relative URI-references.

@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.06% 🎉

Comparison is base (e6f71d0) 92.73% compared to head (ee4620b) 92.80%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
+ Coverage   92.73%   92.80%   +0.06%     
==========================================
  Files          23       23              
  Lines        2052     2070      +18     
  Branches      435      436       +1     
==========================================
+ Hits         1903     1921      +18     
  Misses         97       97              
  Partials       52       52              
Files Changed Coverage Δ
jschon/__init__.py 90.00% <100.00%> (ø)
jschon/catalog/__init__.py 98.35% <100.00%> (+0.18%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@handrews
Copy link
Contributor Author

handrews commented Jul 19, 2023

Looking back over this, it is also something I have semi-re-implemented in oascomply, although I did something a bit different because I also needed to add support for loading YAML, plus all combinations of local/remote/rewritten sources and formats 😬 [EDIT: if this PR is accepted, I'll probably align the oascomply work with it]

This is definitely a PR that could go into jschon as it's not incredibly obvious, or could be published as a separate package of extensions if it feels outside of the core features.

This allows constructing sources that rewrite the URIs requested
so that the URI structure and storage layout can have a more
complex relationship.

This particularly facilitates references to schema resources
embedded in bundles, or references to URI components that use
characters not allowed in filesystems, or a unified URI namespace
that is distributed across multiple repositories in a test environment.
Otherwise, if it's changed, the resource loading behavior
will change, which is probably bad and definitely surprising.
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.

Support instantiating mutually referencing schema bundles
2 participants