# `Infusion.Normalize`
[🔗](https://github.com/mandar1045/infusion/blob/v0.1.0/lib/infusion/normalize.ex#L1)

Rewrites the schemas of a resolved document (see `Infusion.Ref`) into one
canonical form, so the rest of the generator only ever sees one shape.

## Nullability

Real specs say "this can be null" in several ways. All become a single
`"type"` (when there is one) plus `"nullable" => true`:

  * 3.0: `{"type": "string", "nullable": true}`
  * 3.1: `{"type": ["string", "null"]}`
  * 3.1 unions with null: `{"anyOf": [{"$ref": "..."}, {"type": "null"}]}`
    becomes the other variant, nullable. With several other variants the
    union stays, minus the null variant, and is marked nullable.
  * `null` among an `enum`'s values

A 3.1 type list with several non-null types (`["string", "integer"]`) stays
a list.

## `allOf`

A schema built with `allOf` is merged into one schema: properties and
`required` are combined, referenced members are followed, and the schema's
own keywords win over its members'. The names of referenced members are
kept in `"x-infusion-all-of"`.

When two members define the same property, the later one wins. A warning
is returned only when they are incompatible: different types, or different
named schemas. A later member narrowing a loosely defined property (the
response-envelope pattern, where a shared base declares `result` and each
endpoint gives it a real type) is intended and stays silent. When a member is itself a union (`oneOf` /
`anyOf`) the schema can't be merged safely: it is left as it is, with a
warning.

# `warning`

```elixir
@type warning() :: %{path: String.t(), message: String.t()}
```

# `run`

```elixir
@spec run(map()) :: {:ok, map(), [warning()]}
```

Normalizes every schema in `document`. Returns the document and the
warnings found.

---

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