Exonerate.Context (exonerate v1.2.2)

Copy Markdown View Source

Compilation context for JSON Schema validation.

This module provides both the struct for tracking compilation state and the macros for generating validation code.

Struct Fields

  • :resource - Current resource URI (String.t())
  • :pointer - Current JSON pointer (JsonPtr.t())
  • :caller - Caller environment (Macro.Env.t())
  • :only - Type constraints for combining schemas ([String.t()] | nil)

  • :tracked - Tracking mode for unevaluated properties/items (:object | :array | nil)

  • :seen - Seen property tracking (MapSet.t() | nil)

  • :entrypoint - Original entrypoint pointer (JsonPtr.t())
  • :dump - Debug dump mode (boolean)
  • :decoders - Decoder configuration (list)
  • :content_type - Content type / MIME type (String.t())
  • :draft - JSON Schema draft version (atom)
  • :format - Format validation mode (atom | keyword | boolean)

Naming Conventions

  • local_schema = the JSON schema content at current pointer (a map)
  • ctx = Context struct (used internally)
  • opts = keyword list (only at macro boundaries in quote blocks)

Summary

Functions

Collects all declarations by walking the schema structure.

Updates the type constraint (:only) by intersecting with new types.

Creates a new Context from keyword options.

Returns the type constraints as a list, or a default list if not set.

Merges keyword options into an existing Context.

Scrubs combining-specific options from the context.

Scrubs combining-specific options from keyword opts.

Converts a Context to keyword options.

Sets the tracked mode for the context.

Types

t()

@type t() :: %Exonerate.Context{
  caller: Macro.Env.t() | nil,
  content_type: String.t() | nil,
  decimal: :all | keyword() | nil,
  decoders: list() | nil,
  draft: atom() | nil,
  dump: boolean() | nil,
  entrypoint: JsonPtr.t() | nil,
  format: atom() | keyword() | boolean() | nil,
  only: [String.t()] | nil,
  pointer: JsonPtr.t() | nil,
  resource: String.t() | nil,
  seen: MapSet.t() | nil,
  tracked: :object | :array | nil
}

Functions

collect_declarations(module, resource, pointer, opts)

@spec collect_declarations(module(), String.t(), JsonPtr.t(), keyword()) :: :ok

Collects all declarations by walking the schema structure.

This is Phase 1 of the two-phase compilation. It must be called before any code generation macros are invoked.

constrain_types(ctx, types)

@spec constrain_types(t(), [String.t()] | String.t()) :: t()

Updates the type constraint (:only) by intersecting with new types.

This accumulates type restrictions through combining schemas.

fallthrough(resource, pointer, opts, expected_types)

(macro)

filter(resource, pointer, opts)

(macro)

from_opts(opts)

@spec from_opts(keyword()) :: t()

Creates a new Context from keyword options.

get_only(context, default)

@spec get_only(t(), [String.t()]) :: [String.t()]

Returns the type constraints as a list, or a default list if not set.

merge(ctx, opts)

@spec merge(
  t(),
  keyword()
) :: t()

Merges keyword options into an existing Context.

scrub(ctx)

@spec scrub(t()) :: t()

Scrubs combining-specific options from the context.

The following fields are cleared:

  • :only
  • :tracked
  • :seen

scrub_opts(opts)

@spec scrub_opts(keyword()) :: keyword()

Scrubs combining-specific options from keyword opts.

to_opts(ctx)

@spec to_opts(t()) :: keyword()

Converts a Context to keyword options.

with_tracked(ctx, tracked)

@spec with_tracked(t(), :object | :array | nil) :: t()

Sets the tracked mode for the context.