Exonerate.Declaration (exonerate v1.2.2)

Copy Markdown View Source

Represents a function declaration for the two-phase compilation system.

This struct is used during the declaration collection phase to track all functions that need to be generated, their return types, and dependencies between functions. This allows consistent function naming and type inference across the entire schema.

Fields

  • :name - The function name as an atom
  • :resource - The resource URI (String.t())
  • :pointer - The JSON pointer (JsonPtr.t())
  • :opts - Compilation options (keyword or CompilationContext.t())
  • :return_type - Expected return type (:ok | :ok_mapset | :ok_integer | :error | :unknown)

  • :dependencies - List of function names this function calls
  • :degeneracy - Whether the schema is always true, always false, or unknown (:ok | :error | :unknown)

Summary

Functions

Adds a dependency to this declaration.

Determines the return type based on tracking mode.

Creates a new declaration from resource, pointer, and options/context.

Sets the degeneracy status and updates the return type accordingly.

Types

return_type()

@type return_type() :: :ok | :ok_mapset | :ok_integer | :error | :unknown

t()

@type t() :: %Exonerate.Declaration{
  degeneracy: :ok | :error | :unknown | nil,
  dependencies: [atom()] | nil,
  name: atom() | nil,
  opts: keyword() | Exonerate.Context.t() | nil,
  pointer: JsonPtr.t() | nil,
  resource: String.t() | nil,
  return_type: return_type() | nil
}

Functions

add_dependency(decl, dep_name)

@spec add_dependency(t(), atom()) :: t()

Adds a dependency to this declaration.

infer_return_type(declaration)

@spec infer_return_type(t()) :: return_type()

Determines the return type based on tracking mode.

new(resource, pointer, ctx_or_opts)

@spec new(String.t(), JsonPtr.t(), keyword() | Exonerate.Context.t()) :: t()

Creates a new declaration from resource, pointer, and options/context.

with_degeneracy(decl, degeneracy)

@spec with_degeneracy(t(), :ok | :error | :unknown) :: t()

Sets the degeneracy status and updates the return type accordingly.