oaspec/config

Types

Configuration for oaspec code generation.

Opaque: external callers construct via new/6 and read fields via the accessors below. Mutators (with_mode, with_validate, with_output) live in this module too, so every change to a Config value goes through an explicit function.

pub opaque type Config

Errors that can occur when loading config.

pub type ConfigError {
  FileNotFound(path: String)
  FileReadError(path: String, detail: String)
  ParseError(detail: String)
  MissingField(field: String)
  InvalidValue(field: String, detail: String)
}

Constructors

  • FileNotFound(path: String)
  • FileReadError(path: String, detail: String)
  • ParseError(detail: String)
  • MissingField(field: String)
  • InvalidValue(field: String, detail: String)

Generation mode.

pub type GenerateMode {
  Server
  Client
  Both
}

Constructors

  • Server
  • Client
  • Both

Values

pub fn error_to_string(error: ConfigError) -> String

Convert config error to a human-readable string.

pub fn input(cfg: Config) -> String

Path to the OpenAPI spec this config was built for.

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

Load config from a YAML file.

pub fn mode(cfg: Config) -> GenerateMode

Generation mode: server, client, or both.

pub fn new(
  input input: String,
  output_server output_server: String,
  output_client output_client: String,
  package package: String,
  mode mode: GenerateMode,
  validate validate: Bool,
) -> Config

Construct a new Config from its six fields. Prefer load/1 in production code; new/6 is primarily for tests and ad-hoc tooling that assembles a config in memory.

pub fn output_client(cfg: Config) -> String

Output directory for client-side generated files.

pub fn output_server(cfg: Config) -> String

Output directory for server-side generated files.

pub fn package(cfg: Config) -> String

Gleam package name (module prefix) for generated files.

pub fn parse_mode(
  mode: String,
) -> Result(GenerateMode, ConfigError)

Parse a mode string into GenerateMode.

pub fn validate(cfg: Config) -> Bool

Whether guard-based runtime validation is enabled.

pub fn validate_output_package_match(
  config: Config,
) -> Result(Nil, ConfigError)

Validate that output directory basenames match the package name. Gleam imports require import <package>/types, so the directory must match.

pub fn with_mode(config: Config, mode: GenerateMode) -> Config

Apply CLI overrides to a config.

pub fn with_output(
  config: Config,
  output: option.Option(String),
) -> Config

Apply output base directory override. Derives server/client paths as

/ and _client/.

pub fn with_validate(config: Config, validate: Bool) -> Config

Apply validation mode override.

Search Document