# `Infusion.Gen.Schemas`
[🔗](https://github.com/mandar1045/infusion/blob/v0.1.0/lib/infusion/gen/schemas.ex#L1)

Generates one module per named schema.

Objects become structs:

    defmodule OpenAI.Schemas.ChatCompletion do
      @moduledoc "..."
      defstruct [:id, :choices, ..., __extra__: %{}, __present__: []]
      @type t :: %__MODULE__{id: String.t(), choices: [OpenAI.Schemas.Choice.t()], ...}
      def __schema__(:fields), do: [{:id, "id", :string}, ...]
      def decode(json), do: Infusion.Runtime.Schema.decode_module(json, __MODULE__)
    end

Other schemas (enums, unions, arrays, scalars) get a module with a type,
so every reference works the same way. Decoding itself lives in
`infusion_runtime`; the generated code only describes the fields.

# `file`

```elixir
@type file() :: %{module: String.t(), path: String.t(), source: String.t()}
```

# `render`

```elixir
@spec render(
  %Infusion.IR{
    auth: term(),
    operations: term(),
    schemas: term(),
    servers: term(),
    warnings: term()
  },
  String.t()
) :: {[file()], %{required(String.t()) =&gt; String.t()}}
```

Renders every named schema of `ir` under `base` (`"OpenAI"`). Returns the
files and the schema-name-to-module mapping.

---

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