Declares the fields of a command, a parameter object or a nested type.
defmodule MyApp.Authors.Address do
use Arc.Schema
schema do
field :street, :string, required: true
field :city, :string
end
endschema defines the struct and records typed metadata that Arc uses to bind requests,
validate input and generate TypeScript.
Field options
:required- the value must be present (client rulenotEmpty):nullable- the value may benil; defaults totrueunless:required:key- this field identifies the command's event source:default- the struct default:doc- documentation, written into the generated proxy:min_length,:max_length,:email,:matches(a regex source string),:min,:max,:greater_than,:less_than- declarative rules, evaluated on the server and written into the generated validators
Summary
Functions
Binds a wire map (string keys, camelCase) to the struct of module.
Declares one field. See the module documentation for options.
The fields of any struct module: declared fields for an Arc schema, otherwise inferred from the
struct's defaults (for example a Chronicle read model). An nil default is inferred as a string,
matching how Chronicle registers it.
Groups field/3 declarations and defines the struct, so %__MODULE__{} can be used in the
functions that follow.
Functions
@spec cast(module(), map()) :: {:ok, struct()} | {:error, [Arc.ValidationResult.t()]}
Binds a wire map (string keys, camelCase) to the struct of module.
Returns {:ok, struct} or {:error, results} where each result has reason "malformedRequest".
Unknown fields are ignored.
Declares one field. See the module documentation for options.
@spec model_fields(module()) :: [Arc.Schema.Field.t()]
The fields of any struct module: declared fields for an Arc schema, otherwise inferred from the
struct's defaults (for example a Chronicle read model). An nil default is inferred as a string,
matching how Chronicle registers it.
Groups field/3 declarations and defines the struct, so %__MODULE__{} can be used in the
functions that follow.