# `Arc.Schema`
[🔗](https://github.com/Cratis/Arc.Elixir/blob/main/lib/arc/schema.ex#L4)

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
    end

`schema` 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 rule `notEmpty`)
  * `:nullable` - the value may be `nil`; defaults to `true` unless `: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

# `cast`

```elixir
@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.

# `field`
*macro* 

Declares one field. See the module documentation for options.

# `model_fields`

```elixir
@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.

# `schema`
*macro* 

Groups `field/3` declarations and defines the struct, so `%__MODULE__{}` can be used in the
functions that follow.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
