Normandy.Schema (normandy v0.2.0)

View Source

Provides a macro-based DSL for defining structured data schemas.

This module allows you to define structs with typed fields, default values, validation rules, and metadata. It's the foundation for defining agents, messages, and other structured data in Normandy.

Features

  • Type-safe field definitions
  • Default value support
  • Field-level validation
  • Automatic struct generation
  • Metadata tracking
  • Field redaction support

Example

defmodule User do
  use Normandy.Schema

  schema do
    field(:name, :string, required: true)
    field(:age, :integer, default: 0)
    field(:email, :string, required: true)
  end
end

user = %User{name: "Alice", email: "alice@example.com"}

Summary

Types

schema()

@type schema() :: %{
  optional(atom()) => any(),
  __struct__: atom(),
  __meta__: Normandy.Metadata.t()
}

t()

@type t() :: schema()

Functions

field(name, type \\ :string, opts \\ [])

(macro)