Zot.Struct behaviour (zot v0.14.0)

View Source

Notation for defining a struct with schema validation using Zot.

defmodule MyApp.PayoutCreated do
  use Zot.Struct

  schema env: Z.enum([:live, :sandbox]),
         wallet_id: Z.uuid(:v7),
         amount: Z.decimal(gt: 0),
         platform_fee: Z.decimal(gt: 0)
end

Summary

Callbacks

Returns metadata about the module.

Returns a new struct where its fields have been parsed/validated.

Same as new/1 but raises an error if failed to new the given params.

Callbacks

meta(atom)

@callback meta(:schema) :: Zot.Type.Map.t()
@callback meta(:fields) :: [atom(), ...]

Returns metadata about the module.

new(params, opts)

@callback new(params, opts) :: {:ok, struct()} | {:error, [Zot.Issue.t(), ...]}
when params: map() | keyword(), opts: keyword()

Returns a new struct where its fields have been parsed/validated.

new!(params, opts)

@callback new!(params, opts) :: struct() when params: map() | keyword(), opts: keyword()

Same as new/1 but raises an error if failed to new the given params.