fix(schema): replace deprecated jsonschema.RefResolver with referencing.Registry#438
Merged
Conversation
jsonschema.RefResolver was deprecated in v4.18.0 in favour of referencing.Registry. This commit: - Adds _schema_uri() helper (canonical file:// URI from a path) - Adds _build_schema_registry() to pre-load all schemata/*.json so cross-schema $ref values (shared_definitions.json, edition.schema.json) resolve without a base-URI resolver - Sets the schema's 'id' field before validation so Draft4Validator's internal Resolver has the correct base URI for relative $ref lookup - Updates tests/schemata/test_import_schema.py to use the same pattern - Removes unsupported ruff 'show-source' option from pyproject.toml All 46 tests pass, no RefResolver deprecation warnings.
This was referenced Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
jsonschema.RefResolverwas deprecated in v4.18.0 and the warning fires on everyol.validate()call. This PR replaces it with thereferencing.RegistryAPI.Changes
olclient/openlibrary.py: Add_schema_uri()helper and_build_schema_registry()that pre-loads allschemata/*.jsonfiles into aRegistry. Thevalidate()method now injects the schema's ownid(Draft4's base URI field) before callingDraft4Validator(..., registry=registry), so relative$refvalues likeshared_definitions.json#/string_arrayresolve correctly.tests/schemata/test_import_schema.py: Same pattern — uses_build_schema_registry+ injectedidinstead ofRefResolver.pyproject.toml: Removeshow-source = truefrom[tool.ruff]— this option was removed in modern ruff and causes a config error.Testing
The 4 remaining warnings are from
backoff's internal use ofasyncio.iscoroutinefunction(a third-party package deprecation in Python 3.14, not actionable here). ZerojsonschemaorRefResolverdeprecation warnings.Note on cross-schema
$refresolutionThe tricky part:
import.schema.jsonreferencesshared_definitions.jsonandedition.schema.jsonvia relative$ref. The oldRefResolverresolved these relative to the base URI directory automatically. The newRegistryrequires all referenced schemas to be pre-loaded AND the root schema needs anidfield set to its own URI soDraft4Validator's internalResolverhas a non-empty base URI to resolve relative paths against.Relates to open PR #430 (same issue, different implementation).