Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.

Conversation

@handrews
Copy link
Contributor

Fixes #68 (2nd try, now with much more testing!) , although I'm submitting it as a draft to indicate that I'm not particularly confident that this is the ideal way to solve it. But it's a starting point, at least.

This change allows the tests added in PR json-schema-org/JSON-Schema-Test-Suite#646 (updated here in PR #67) to pass, in accordance with §9.3.1 of the spec, "Detecting a Meta-Schema".

  • Catalog.get_metaschema() is added, and is analogous in behavior to Catalog.get_schema(), checking the __meta__ cache directly and then relying on Catalog.create_metaschema() to avoid needlessly creating both JSONSchema and Metaschema instances.
  • It is called from the now-cached JSONSchema.metaschema property, to keep the parallel with references which are only resolved when used.
  • Catalog.create_metaschema() now returns the created metaschema to avoid having to immediately look it up again, as does Catalog.create_vocabulary()
  • The core_vocabulary parameters have become default_core_vocabulary parameters to allow not knowing the core in advance
    *The Metaschema constructor now looks in "$vocabulary" for a vocabulary URI matching r'^https://json-schema\.org/draft/[^/]*/core$ and if it finds a unique match, uses that instead of the default
  • Lack of a recognizable core vocabulary still results in a JSONSchemaError exception if no default is provided
  • I wasn't entirely sure where to put the Metaschema test cases, so the Catalog-related ones went into that test file and the constructor ones went into a new test_metaschema.py

Note that the fixture is a separate commit because it is shared with the next PR I'm about to post.

@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2023

Codecov Report

Patch coverage: 93.75% and project coverage change: +0.43 🎉

Comparison is base (f0a4e16) 90.98% compared to head (c1c6f72) 91.42%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #71      +/-   ##
==========================================
+ Coverage   90.98%   91.42%   +0.43%     
==========================================
  Files          21       21              
  Lines        1986     2006      +20     
  Branches      422      427       +5     
==========================================
+ Hits         1807     1834      +27     
+ Misses        118      113       -5     
+ Partials       61       59       -2     
Impacted Files Coverage Δ
jschon/catalog/_2019_09.py 100.00% <ø> (ø)
jschon/catalog/_2020_12.py 100.00% <ø> (ø)
jschon/catalog/_next.py 100.00% <ø> (ø)
jschon/vocabulary/__init__.py 90.21% <92.30%> (+3.96%) ⬆️
jschon/catalog/__init__.py 91.55% <94.11%> (+1.55%) ⬆️
jschon/jsonschema.py 89.61% <100.00%> (+0.64%) ⬆️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

This will be used to test several forthcoming changes.
This change allows the tests added in
PR json-schema-org/JSON-Schema-Test-Suite#646 to pass,
in accordance with §9.3.1 of the spec, "Detecting a Meta-Schema".

* Catalog.get_metaschema() is added, and is analogous in behavior
  to Catalog.get_schema(), relying on Catalog.create_metaschema()
* It is called from the now-cached JSONSchema.metaschema property,
  to keep the parallel with references which are only resolved
  when used
* Catalog.create_metaschema() now returns the created metaschema
  to avoid having to immediately look it up again, as does
  Catalog.create_vocabulary()
* The core_vocabulary parameters have become default_core_vocabulary
  parameters to allow not knowing the core in advance
* The Metaschema constructor now looks in "$vocabulary" for a
  vocabulary URI matching r'^https://json-schema\.org/draft/[^/]*/core'
  and if it finds a unique match, uses that instead of the default
* Lack of a recognizable core vocabulary still results in a
  JSONSchemaError exception if no default is provided
@handrews handrews marked this pull request as ready for review March 24, 2023 04:31
@handrews
Copy link
Contributor Author

Having spent a great deal more time in all the relevant areas of the code, I haven't come up with any better approach, so I've moved this out of draft PR status.

Following 0b1108b, we just need to handle the initially non-existent '__meta__' cache, and then explicit calls to `Catalog.create_metaschema()` can generally be removed.
@marksparkza
Copy link
Owner

Nice work, @handrews! Do you mind if I push to this branch?

@handrews
Copy link
Contributor Author

@marksparkza Thanks! I think I opened this PR with the "allow maintainer to make changes" - thanks for checking but feel free to add commits. What workflow do you have in mind? Are you looking to discuss those additional commits? (Just trying to understand the difference between what you want to do here and merging and then adding things separately).

@handrews
Copy link
Contributor Author

Or did you mean create this branch in your repo rather than going straight to main? I'm also totally fine with that.

@marksparkza
Copy link
Owner

Automated meta-schema creation is a big win, and I think it's worth rounding off this PR by removing boilerplate create_metaschema() calls in catalog setup scripts, and allowing Metaschema instances to be created implicitly. I realised while working through your changes that this could be done with just a couple of tweaks, so I've added two commits locally: one to update the test suite (identical to the one on the testsuite-main branch, which I'll drop), and one to remove boilerplate.

There are one or two changes that I'd still like to take a closer look at, so I may add further comments following the additional commits. Likewise, please feel free to comment on or query any changes that I make to your code.

Once this PR is merged we're in a good position to publish a very long awaited v0.10, so I'm going to go ahead with that and work through the remaining PRs for the next version increment.

@handrews
Copy link
Contributor Author

@marksparkza Sounds great! I will try to finish the PR for the list output format by Monday as I'd like to get that in if possible, but that's the last thing I really wanted to contribute to 0.10.

I have some other things in the works for draft-next support, but that can wait (and TBH I'm about to not have as much time avaialble so they'd probably take a while before I got around to them).

@handrews
Copy link
Contributor Author

handrews commented Mar 27, 2023

Once this PR is merged we're in a good position to publish a very long awaited v0.10, so I'm going to go ahead with that and work through the remaining PRs for the next version increment.

@marksparkza I think I slightly misunderstood you although it doesn't really change anything. Just to be sure I understand: You plan to merge this PR once it's finished and immediately release 0.10.0, correct?

If so, I would recommend also merging the very simple PRs #72 (putting the not-found schema file name in the CatalogError message so it's not so cryptic) and #73 (a few super-simple tests for the Catalog). Both were originally part of this PR that I split out to keep this one more focused. Neither should take long to review.

I'm perfectly happy with the rest (including the list output format that I haven't posted yet) going into 0.11.0 (not that I'd try to veto your package's release schedule anyway, even over the above two PR recommendations!). Would you consider those remaining PRs enough to release 0.11.0 whenever you get through them, or would there be more that you'd want to have in that release?

BTW, when you push the 0.10.0 release, I'll rebase the other PRs and rework their CHANGELOG updates accordingly.

@marksparkza
Copy link
Owner

plan to merge this PR once it's finished and immediately release 0.10.0, correct?

Yes, that's the plan. I'd prefer to merge this PR as is, and subsequently look at 72 and 73 for a 0.10.1 patch. I do appreciate that they are quite straightforward, but they're also relatively insignificant and shouldn't hold up or force a rebase of 71. Having said that, we're looking at a timescale of days rather than months for 0.10.1.

when you push the 0.10.0 release, I'll rebase the other PRs

Thanks, much appreciated. Please just do 72 and 73, and the rest once 0.10.1 is out. I'll be happy to include the list PR in 0.10.1 if you're ready with it. Otherwise, nothing else goes into 0.10.1.

Would you consider those remaining PRs enough to release 0.11.0

Yes, absolutely!

@handrews
Copy link
Contributor Author

@marksparkza thanks for the explanation - that all sounds fantastic! Yes, a 0.10.1 makes sense — I think I am too used to projects that are reluctant to do quick follow-up releases so that simply didn't occur to me.

@marksparkza marksparkza merged commit 1f023e1 into marksparkza:main Apr 1, 2023
@handrews handrews deleted the load-meta branch April 10, 2023 19:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"$schema" access should load a Metaschema like "$ref" access loads a JSONSchema

3 participants