Exdantic.Settings (exdantic v0.1.0)

Copy Markdown View Source

Env-based settings loader for Exdantic schemas.

This module builds schema input from environment variables and explicit input, then delegates validation to the existing Exdantic validation pipeline.

v1 behavior:

  • Field names derive env keys as snake_case -> UPPER_SNAKE, joined by env_nested_delimiter (default "__"), with env_prefix prepended.
  • Field override extra: %{"env" => "KEY"} is absolute; prefix is not applied. If both override and derived key exist, override wins.
  • Structured values (array, maps/objects, nested schema refs) are JSON-only.
  • Union decoding is conservative: JSON is attempted only for JSON-like strings ({ or [) when the union includes structured members; otherwise raw strings are passed to validation.
  • Exploded nested env keys do not address arrays in v1 (APP_ITEMS__0 is ignored).

Summary

Types

load_option()

@type load_option() ::
  {:input, map()}
  | {:env, map()}
  | {:env_prefix, String.t()}
  | {:env_nested_delimiter, String.t()}
  | {:case_sensitive, boolean()}
  | {:ignore_empty, boolean()}
  | {:allow_atoms, false | :existing}
  | {:bool_numeric, boolean()}

Functions

from_system_env(schema_module, opts \\ [])

@spec from_system_env(module(), [load_option()]) ::
  {:ok, map() | struct()} | {:error, [Exdantic.Error.t()]}

load(schema_module, opts \\ [])

@spec load(module(), [load_option()]) ::
  {:ok, map() | struct()} | {:error, [Exdantic.Error.t()]}

load!(schema_module, opts \\ [])

@spec load!(module(), [load_option()]) :: map() | struct()