Resolving JSON References#

class jsonschema.RefResolver(base_uri, referrer, store=(), cache_remote=True, handlers=(), urljoin_cache=None, remote_cache=None)[source]#

Resolve JSON References.

Parameters:
  • base_uri (str) – The URI of the referring document

  • referrer – The actual referring document

  • store (dict) – A mapping from URIs to documents to cache

  • cache_remote (bool) – Whether remote refs should be cached after first resolution

  • handlers (dict) – A mapping from URI schemes to functions that should be used to retrieve them

  • urljoin_cache (functools.lru_cache()) – A cache that will be used for caching the results of joining the resolution scope to subscopes.

  • remote_cache (functools.lru_cache()) – A cache that will be used for caching the results of resolved remote URLs.

cache_remote#

Whether remote refs should be cached after first resolution

Type:

bool

property base_uri#

Retrieve the current base URI, not including any fragment.

classmethod from_schema(schema, id_of=<function _id_of>, *args, **kwargs)[source]#

Construct a resolver from a JSON schema object.

Parameters:

schema – the referring schema

Returns:

RefResolver

in_scope(scope)[source]#

Temporarily enter the given scope for the duration of the context.

pop_scope()[source]#

Exit the most recent entered scope.

Treats further dereferences as being performed underneath the original scope.

Don’t call this method more times than push_scope has been called.

push_scope(scope)[source]#

Enter a given sub-scope.

Treats further dereferences as being performed underneath the given scope.

property resolution_scope#

Retrieve the current resolution scope.

resolve(ref)[source]#

Resolve the given reference.

resolve_fragment(document, fragment)[source]#

Resolve a fragment within the referenced document.

Parameters:
  • document – The referent document

  • fragment (str) – a URI fragment to resolve within it

resolve_from_url(url)[source]#

Resolve the given remote URL.

resolve_remote(uri)[source]#

Resolve a remote uri.

If called directly, does not check the store first, but after retrieving the document at the specified URI it will be saved in the store if cache_remote is True.

Note

If the requests library is present, jsonschema will use it to request the remote uri, so that the correct encoding is detected and used.

If it isn’t, or if the scheme of the uri is not http or https, UTF-8 is assumed.

Parameters:

uri (str) – The URI to resolve

Returns:

The retrieved document

resolving(ref)[source]#

Resolve the given ref and enter its resolution scope.

Exits the scope on exit of this context manager.

Parameters:

ref (str) – The reference to resolve

exception jsonschema.RefResolutionError(cause)[source]#

A ref could not be resolved.

A JSON reference failed to resolve.