NAME
std/data/json/schema/core - JSON Schema resources and reference registry.
SYNOPSIS
from std/data/json/schema/core import SchemaRegistry;
let registry := new SchemaRegistry();
registry.register( address_schema, "https://example.test/address" );
let subschema := registry.resolve(
"https://example.test/address#/properties/postcode",
);
IMPLEMENTATION SUPPORT
This Pure Zuzu module is supported by all implementations of ZuzuScript. HTTPResourceLoader requires std/net/http and dies at construction time when that module is unavailable.
DESCRIPTION
This module contains the resource and reference support used by std/data/json/schema. It registers schemas under base URIs, indexes $id, $anchor, and $dynamicAnchor, and resolves references to either whole resources or JSON Pointer fragments.
Most callers should use JSONSchema from std/data/json/schema. Import this module directly when schemas need to share a registry or when reference loading needs to be customised.
EXPORTS
Classes
SchemaRegistryStores schema resources and resolves references.
register( schema, uri := "" )Registers
schemaaturi, indexes nested$idvalues and anchors, and returns the registry.set_loader( loader )Sets the loader used for missing resources. A loader may be a callable or an object with a
load(uri)method. Loaded strings are decoded as JSON before being registered.resolve( ref, base := "" )Resolves
refagainstbase. Empty fragments return the resource. Anchor fragments use the registry's anchor index. Pointer fragments are resolved with std/path/jsonpointer. Failure to find a resource or target throws an exception.
HTTPResourceLoaderSimple HTTP and HTTPS loader.
load(uri)fetchesuriwithstd/net/httpand returns the response content after requiring a successful response.
Functions
jschema_uri_resolve( base, ref )Resolves the URI reference
refagainstbasefor the subset of URI resolution needed by this validator.jschema_url_split( url )Returns a
Dictwithbaseurlandfragment.fragmentisnullwhenurlhas no#.
COPYRIGHT AND LICENCE
std/data/json/schema/core is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.