# `Kotoba.Node.Field`
[🔗](https://github.com/hattoriai/kotoba/blob/v0.5.0/lib/kotoba/node/field.ex#L1)

The description of one attribute of a `Kotoba.Node`.

`Kotoba.Node.field/3` makes one `Kotoba.Node.Field` for each attribute.
`c:Kotoba.Node.fields/0` returns them in the order of declaration.

## Struct keys

  * `:name` - the struct key of the node, an atom.
  * `:key` - the JSON key.
  * `:type` - `:string`, `:integer`, `:boolean`, `:map` or `{:array, type}`.
  * `:required`, `:default`, `:in` and `:omit_nil` - the values of the
    options below.

## Options of `field/3`

  * `:key` - the JSON key. The default is the name as a string.
  * `:required` - when `true`, the value must not be `nil`. The default is
    `false`.
  * `:default` - the struct default. `from_json/1` also uses it when the
    JSON has no value for the key. The default is `nil`.
  * `:in` - when set, a list of the permitted values.
  * `:omit_nil` - when `true`, `to_json/1` does not write the key if the
    value is `nil`. When `false` (the default), `to_json/1` writes `null`.

# `t`

```elixir
@type t() :: %Kotoba.Node.Field{
  default: term(),
  in: [term()] | nil,
  key: String.t(),
  name: atom(),
  omit_nil: boolean(),
  required: boolean(),
  type: type()
}
```

# `type`

```elixir
@type type() :: :string | :integer | :boolean | :map | {:array, type()}
```

A field type.

# `check`

```elixir
@spec check(t(), term()) :: :ok | {:error, String.t()}
```

Checks one value against the field. Returns `:ok` or `{:error, message}`.

# `new`

```elixir
@spec new(atom(), type(), keyword()) :: t()
```

Builds a field. Raises `ArgumentError` when the name, the type or an
option is not valid.

---

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