# `JSV.ErrorFormatter`
[🔗](https://github.com/lud/jsv/blob/v0.18.3/lib/jsv/error_formatter.ex#L1)

Error formatting helpers.

Errors are grouped by:

* Instance location: the bit of data that was invalidated
* Schema location: the part of the schema that invalidated it
* Evaluation path: the path followed from the root to this schema location

# `error_unit`

```elixir
@type error_unit() :: %{
  :valid =&gt; boolean(),
  :instanceLocation =&gt; binary(),
  :evaluationPath =&gt; binary(),
  :schemaLocation =&gt; binary(),
  optional(:errors) =&gt; [keyword_error()]
}
```

# `keyword_error`

```elixir
@type keyword_error() :: %{
  :kind =&gt; atom(),
  :message =&gt; String.t(),
  optional(:details) =&gt; [error_unit()]
}
```

# `normalize_opt`

```elixir
@type normalize_opt() :: {:sort, term()} | {:keys, term()}
```

# `raw_path`

```elixir
@type raw_path() :: [raw_path()] | binary() | integer() | atom()
```

# `format_data_path`

```elixir
@spec format_data_path(raw_path()) :: String.t()
```

# `normalize_error`

```elixir
@spec normalize_error(
  JSV.ValidationError.t(),
  keyword()
) :: map()
```

Returns a JSON-able version of the errors contained in the ValidationError.

This is generatlly useful to generate HTTP API responses or message broker
responses.

### Options

* `:sort` - Controls the sort direction. Errors are sorted by `instanceLocation`. The default value is `:desc`.

* `:keys` - Define the type of the keys in the normalized errors maps.

  While truly "normalized" JSON data should not have atom keys,
  this option defaults to :atoms for backward compatibility reasons.

# `valid_annot`

```elixir
@spec valid_annot(JSV.Validator.validator(), JSV.Validator.context()) :: error_unit()
```

Returns an output unit with `valid: true` for the given
`JSV.Validator`. This can be substitued to an Error struct in the
nested details of an error. Mostly used to show multiple validated schemas
with `:oneOf`.

---

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