Infusion.Gen.Schemas (infusion v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

Types

file()

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

Functions

render(ir, base)

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

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