Draft 2020-12 dialect helpers for built-in dialect recognition and
$vocabulary resolution.
This module centralizes the Draft 2020-12-specific pieces that were previously embedded in the generic compiler flow:
- recognition of the canonical Draft 2020-12 meta-schema URI
- default active vocabularies for the built-in Draft 2020-12 dialect
- extraction of enabled vocabularies from a meta-schema's
$vocabulary - validation of required vocabularies against the implementation capability set
- built-in dialect resolution for compiler delegation
It is intentionally small and data-oriented so generic compiler code can delegate draft-specific decisions here.
Examples
iex> JSONSchex.Draft202012.Dialect.builtin_schema_uri()
"https://json-schema.org/draft/2020-12/schema"
iex> JSONSchex.Draft202012.Dialect.builtin_schema?(%{"$schema" => "https://json-schema.org/draft/2020-12/schema"})
true
iex> JSONSchex.Draft202012.Dialect.enabled_vocabularies(%{
...> "$vocabulary" => %{
...> "https://json-schema.org/draft/2020-12/vocab/core" => true,
...> "https://json-schema.org/draft/2020-12/vocab/format-annotation" => false
...> }
...> })
["https://json-schema.org/draft/2020-12/vocab/core",
"https://json-schema.org/draft/2020-12/vocab/format-annotation"]
iex> JSONSchex.Draft202012.Dialect.resolve_builtin(%{"$schema" => "https://json-schema.org/draft/2020-12/schema"})
{:ok,
["https://json-schema.org/draft/2020-12/vocab/core",
"https://json-schema.org/draft/2020-12/vocab/applicator",
"https://json-schema.org/draft/2020-12/vocab/validation",
"https://json-schema.org/draft/2020-12/vocab/unevaluated",
"https://json-schema.org/draft/2020-12/vocab/format-annotation",
"https://json-schema.org/draft/2020-12/vocab/content",
"https://json-schema.org/draft/2020-12/vocab/meta-data"]}
iex> JSONSchex.Draft202012.Dialect.resolve_builtin(%{"$schema" => "https://example.com/custom"})
nil
Summary
Functions
Returns the canonical base URI for Draft 2020-12 resources.
Returns true when the given schema declares the canonical built-in
Draft 2020-12 meta-schema URI.
Returns the canonical built-in Draft 2020-12 meta-schema URI.
Returns the default active vocabularies for the built-in Draft 2020-12 dialect.
Returns the enabled vocabularies for a schema.
Resolves the built-in Draft 2020-12 dialect for a schema.
Returns the full set of vocabularies supported by the implementation for Draft 2020-12 vocabulary validation.
Validates that all required vocabularies declared by the schema are supported.
Returns true if the given vocabulary URI is supported by the implementation.
Functions
@spec base_uri() :: String.t()
Returns the canonical base URI for Draft 2020-12 resources.
Returns true when the given schema declares the canonical built-in
Draft 2020-12 meta-schema URI.
@spec builtin_schema_uri() :: String.t()
Returns the canonical built-in Draft 2020-12 meta-schema URI.
@spec default_active_vocabularies() :: [String.t()]
Returns the default active vocabularies for the built-in Draft 2020-12 dialect.
This excludes format-assertion, matching the standard Draft 2020-12
behavior.
Returns the enabled vocabularies for a schema.
If the schema declares $vocabulary, required vocabularies are always
included, and optional vocabularies are included only when they are supported
by the implementation. If $vocabulary is absent, the provided defaults are
returned unchanged.
Resolves the built-in Draft 2020-12 dialect for a schema.
Returns {:ok, vocabularies} when the schema declares the canonical built-in
Draft 2020-12 meta-schema URI, otherwise returns nil.
@spec supported_vocabularies() :: [String.t()]
Returns the full set of vocabularies supported by the implementation for Draft 2020-12 vocabulary validation.
@spec validate_required_vocabularies(map()) :: :ok | {:error, JSONSchex.Types.Error.t()}
Validates that all required vocabularies declared by the schema are supported.
Returns :ok when valid, otherwise returns a structured
:unsupported_vocabulary error.
Returns true if the given vocabulary URI is supported by the implementation.