std/data/json/schema/core

Standard Library documentation

JSON Schema resources and reference registry.

Module

Name
std/data/json/schema/core
Area
Standard Library
Source
modules/std/data/json/schema/core.zzm

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

  • SchemaRegistry

    Stores schema resources and resolves references.

    • register( schema, uri := "" )

      Registers schema at uri, indexes nested $id values 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 ref against base. 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.

  • HTTPResourceLoader

    Simple HTTP and HTTPS loader. load(uri) fetches uri with std/net/http and returns the response content after requiring a successful response.

Functions

  • jschema_uri_resolve( base, ref )

    Resolves the URI reference ref against base for the subset of URI resolution needed by this validator.

  • jschema_url_split( url )

    Returns a Dict with baseurl and fragment. fragment is null when url has 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.