nori/config

Config file support for the OpenAPI code generator.

Loads a YAML config file that specifies which targets to generate, output directories, and target-specific options.

Types

Top-level configuration.

pub type Config {
  Config(spec: String, output: OutputConfig)
}

Constructors

Errors that can occur when loading a config file.

pub type ConfigError {
  ConfigFileNotFound(path: String)
  ConfigParseError(message: String)
}

Constructors

  • ConfigFileNotFound(path: String)
  • ConfigParseError(message: String)

Output configuration for all targets.

pub type OutputConfig {
  OutputConfig(
    gleam: TargetConfig,
    typescript: TargetConfig,
    react_query: TargetConfig,
    swr: TargetConfig,
    fetch: TargetConfig,
  )
}

Constructors

Configuration for a single code generation target.

pub type TargetConfig {
  TargetConfig(
    enabled: Bool,
    dir: String,
    generated_suffix: Bool,
    dirs: dict.Dict(String, String),
    types_module: String,
    options: dict.Dict(String, String),
  )
}

Constructors

  • TargetConfig(
      enabled: Bool,
      dir: String,
      generated_suffix: Bool,
      dirs: dict.Dict(String, String),
      types_module: String,
      options: dict.Dict(String, String),
    )

    Arguments

    dirs

    Per-file directory overrides, keyed by generated file name (types, routes, client, middleware). Gleam target only.

    A Gleam project is often split backend / frontend / shared, and the four generated modules do not belong to the same one: types is shared, routes and middleware are the backend’s, client is the frontend’s. Anything absent falls back to dir.

    types_module

    Module path the other generated files import types by, for when it lands in a different Gleam project and cannot be derived from the importing file’s own directory. Gleam target only.

Values

pub fn default() -> Config

The default configuration.

⚠️ Only the Gleam target is on by default. nori is a Gleam tool that can also emit TypeScript, and a config that never mentions typescript used to get TypeScript anyway — written to ./generated relative to the cwd, which read as nori generating files nobody asked for. Naming a target in the config is what turns it on.

pub fn default_target(dir: String, suffix: Bool) -> TargetConfig

Creates a default target config with the given dir and suffix setting.

pub fn disabled_target(dir: String, suffix: Bool) -> TargetConfig

A target that is off until the config names it.

pub fn load(path: String) -> Result(Config, ConfigError)

Loads a config from a YAML file.

Search Document