Skip to content

fix(schema): replace deprecated jsonschema.RefResolver with referencing.Registry#438

Merged
mekarpeles merged 1 commit into
masterfrom
impa/fix-ci-deprecations
Jul 2, 2026
Merged

fix(schema): replace deprecated jsonschema.RefResolver with referencing.Registry#438
mekarpeles merged 1 commit into
masterfrom
impa/fix-ci-deprecations

Conversation

@mekarpeles

Copy link
Copy Markdown
Member

Summary

jsonschema.RefResolver was deprecated in v4.18.0 and the warning fires on every ol.validate() call. This PR replaces it with the referencing.Registry API.

Changes

  • olclient/openlibrary.py: Add _schema_uri() helper and _build_schema_registry() that pre-loads all schemata/*.json files into a Registry. The validate() method now injects the schema's own id (Draft4's base URI field) before calling Draft4Validator(..., registry=registry), so relative $ref values like shared_definitions.json#/string_array resolve correctly.
  • tests/schemata/test_import_schema.py: Same pattern — uses _build_schema_registry + injected id instead of RefResolver.
  • pyproject.toml: Remove show-source = true from [tool.ruff] — this option was removed in modern ruff and causes a config error.

Testing

$ pytest tests/ -q
46 passed, 4 warnings

The 4 remaining warnings are from backoff's internal use of asyncio.iscoroutinefunction (a third-party package deprecation in Python 3.14, not actionable here). Zero jsonschema or RefResolver deprecation warnings.

Note on cross-schema $ref resolution

The tricky part: import.schema.json references shared_definitions.json and edition.schema.json via relative $ref. The old RefResolver resolved these relative to the base URI directory automatically. The new Registry requires all referenced schemas to be pre-loaded AND the root schema needs an id field set to its own URI so Draft4Validator's internal Resolver has a non-empty base URI to resolve relative paths against.

Relates to open PR #430 (same issue, different implementation).

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.
@mekarpeles
mekarpeles merged commit 4d0b8d4 into master Jul 2, 2026
3 checks passed
@mekarpeles
mekarpeles deleted the impa/fix-ci-deprecations branch July 2, 2026 04:11
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.

1 participant