ZoiForge (ZoiForge v0.1.0)

Copy Markdown View Source

Generate typed, documented Elixir modules from JSON Schema files using Zoi.

ZoiForge is a code generator: point it at a directory of *.schema.json files and it writes Elixir modules with compile-time @type t, runtime parse/1, and docs derived from each schema. It works with any JSON Schema files on disk — no Rusl dependency required.

Quick start

Configure defaults (optional):

config :zoi_forge,
  source_dir: "priv/schemas",
  output_dir: "lib/schemas"

Generate modules:

mix zoi_forge.gen

Or call the generator directly:

ZoiForge.Generator.run(
  prefix: "MyApp",
  source_dir: "priv/schemas",
  output_dir: "lib/schemas"
)

Generated modules

Each schema file becomes a module exposing:

  • @type t — Elixir type from the JSON Schema
  • schema/0 — parsed Zoi schema
  • raw_schema/0 — original JSON Schema string
  • parse/1Zoi.parse/2 wrapper

Schemas with $defs also emit nested modules for individual definitions.

Mix tasks

See Mix.Tasks.ZoiForge.Gen for CLI switches and configuration details.