JSONSchex.Draft202012.Schemas (jsonschex v0.6.0)

Copy Markdown View Source

Provides built-in JSON Schema resources bundled directly in the module.

This module embeds the canonical Draft 2020-12 meta-schema family as Elixir maps, avoiding runtime file reads and JSON decoding. It also exposes a compiled defs registry so built-in $ref and $dynamicRef targets can participate in normal runtime resolution.

The public API is intentionally small:

Summary

Functions

Returns the compiled defs registry for the built-in schema family containing the given URI.

Fetches a bundled schema by canonical URI.

Returns true if the given URI is bundled with the library.

Functions

compiled_defs(uri)

@spec compiled_defs(String.t()) :: map() | nil

Returns the compiled defs registry for the built-in schema family containing the given URI.

The returned map includes:

  • each built-in resource under its canonical absolute URI
  • all compiled defs discovered within each resource
  • all $anchor and $dynamicAnchor absolute entries discovered by scanning the raw built-in resources

This allows built-in schemas to behave like a normal compiled defs registry during $ref and $dynamicRef resolution.

fetch(uri)

@spec fetch(String.t()) :: {:ok, map()} | :error

Fetches a bundled schema by canonical URI.

Returns {:ok, map} when the URI is known, otherwise returns :error.

Examples

iex> {:ok, schema} = JSONSchex.Draft202012.Schemas.fetch("https://json-schema.org/draft/2020-12/schema")
iex> is_map(schema)
true

iex> JSONSchex.Draft202012.Schemas.fetch("https://example.com/custom")
:error

known_uri?(uri)

@spec known_uri?(String.t()) :: boolean()

Returns true if the given URI is bundled with the library.

Examples

iex> JSONSchex.Draft202012.Schemas.known_uri?("https://json-schema.org/draft/2020-12/schema")
true

iex> JSONSchex.Draft202012.Schemas.known_uri?("https://example.com/custom")
false