nori/yaml

YAML parsing support for OpenAPI specifications.

Uses taffy (yaml package) for YAML parsing, then bridges to the existing JSON decoder via a JSON roundtrip. This avoids duplicating the ~1000-line decoder while adding full YAML support.

Types

Errors that can occur during YAML parsing.

pub type YamlParseError {
  YamlSyntaxError(message: String)
  YamlDecodeError(errors: List(decode.DecodeError))
  FileError(path: String, message: String)
}

Constructors

  • YamlSyntaxError(message: String)

    YAML syntax error

  • YamlDecodeError(errors: List(decode.DecodeError))

    JSON conversion or decoding failed

  • FileError(path: String, message: String)

    File could not be read

Values

pub fn load_yaml_file(
  path: String,
) -> Result(value.YamlValue, YamlParseError)

Loads a file and returns the raw YamlValue (useful for $ref resolution).

pub fn parse_file(
  path: String,
) -> Result(document.Document, YamlParseError)

Loads and parses an OpenAPI spec file (YAML or JSON).

Detects format by file extension:

  • .yaml, .yml → YAML parsing
  • .json → JSON parsing
  • Other → tries YAML first, falls back to JSON
pub fn parse_yaml(
  input: String,
) -> Result(document.Document, YamlParseError)

Parses a YAML string into an OpenAPI Document.

Examples

let yaml_str = "openapi: '3.1.0'\ninfo:\n  title: My API\n  version: '1.0.0'"
let assert Ok(doc) = parse_yaml(yaml_str)
pub fn yaml_value_to_document(
  value: value.YamlValue,
) -> Result(document.Document, YamlParseError)

Converts a parsed YamlValue into an OpenAPI Document.

Search Document