summaryrefslogtreecommitdiff
path: root/jsonschema/protocols.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2023-02-16 12:32:00 +0200
committerJulian Berman <Julian@GrayVines.com>2023-02-21 09:58:40 +0200
commite8266294408521daf38d879ba35c45a4b0ef5180 (patch)
tree0dba5b9aafc21b65d0a48b744cea021770e8e9d9 /jsonschema/protocols.py
parenta39e5c953a559b287c753bd604e3e11d218c29cf (diff)
downloadjsonschema-e8266294408521daf38d879ba35c45a4b0ef5180.tar.gz
Resolve $ref using the referencing library.
Passes all the remaining referencing tests across all drafts, hooray! Makes Validators take a referencing.Registry argument which users should use to customize preloaded schemas, or to configure remote reference retrieval. This fully obsoletes jsonschema.RefResolver, which has already been deprecated in a previous commit. Users should move to instead loading schemas into referencing.Registry objects. See the referencing documentation at https://referencing.rtfd.io/ for details (with more jsonschema-specific information to be added shortly). Note that the interface for resolving references on a Validator is not yet public (and hidden behind _resolver and _validate_reference attributes). One or both of these are likely to become public after some period of stabilization. Feedback is of course welcome!
Diffstat (limited to 'jsonschema/protocols.py')
-rw-r--r--jsonschema/protocols.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/jsonschema/protocols.py b/jsonschema/protocols.py
index eb67444..9d34f61 100644
--- a/jsonschema/protocols.py
+++ b/jsonschema/protocols.py
@@ -11,6 +11,8 @@ from collections.abc import Callable, Mapping
from typing import TYPE_CHECKING, Any, ClassVar, Iterable
import sys
+from referencing.jsonschema import SchemaRegistry
+
# doing these imports with `try ... except ImportError` doesn't pass mypy
# checking because mypy sees `typing._SpecialForm` and
# `typing_extensions._SpecialForm` as incompatible
@@ -60,6 +62,10 @@ class Validator(Protocol):
an invalid schema can lead to undefined behavior. See
`Validator.check_schema` to validate a schema first.
+ registry:
+
+ a schema registry that will be used for looking up JSON references
+
resolver:
a resolver that will be used to resolve :kw:`$ref`
@@ -113,6 +119,7 @@ class Validator(Protocol):
def __init__(
self,
schema: Mapping | bool,
+ registry: SchemaRegistry,
format_checker: jsonschema.FormatChecker | None = None,
) -> None:
...