openapi_to_moonbit

    General-purpose OpenAPI 3.0 & 3.1 to MoonBit HTTP, streaming, and WebSocket client generator (sans-IO library + native CLI).

    openapi
    codegen
    moonbit
    http
    client
    cli
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    8 hours ago
    Downloads
    7

    #vigoo/openapi_to_moonbit

    General-purpose OpenAPI 3.0 & 3.1 → MoonBit HTTP, streaming, and WebSocket client generator.

    Emits clean, formatted, multi-backend MoonBit client packages backed by vigoo/openapi_client_runtime and vigoo/moonbit_codegen.

    #Install

    Add as a MoonBit library dependency (pure / sans-IO across native, js, wasm, and wasm-gc):

    moon add vigoo/openapi_to_moonbit

    Or run the native CLI directly from source:

    moon run --target native openapi_to_moonbit/cmd/openapi_moonbit -- --help

    #Packages

    PackageTargetsPurpose
    vigoo/openapi_to_moonbitnative, js, wasm, wasm-gcTop-level facade: Pipeline, load_yaml, load_json, build_ir, diff_specs, diff_ir, generate, inspect_report.
    vigoo/openapi_to_moonbit/specnative, js, wasm, wasm-gcOpenAPI 3.0/3.1 YAML & JSON loader, multi-spec merger, OpenAPI Overlays 1.0 engine, and sans-IO external $ref bundler.
    vigoo/openapi_to_moonbit/irnative, js, wasm, wasm-gcSemantic IR lowering (allOf, discriminated & untagged unions, 4-state presence, readOnly/writeOnly splitting, tag grouping), IrHooks, and diff_ir.
    vigoo/openapi_to_moonbit/confignative, js, wasm, wasm-gcYAML & programmatic GeneratorConfig with validation.
    vigoo/openapi_to_moonbit/gennative, js, wasm, wasm-gcDeterministic MoonBit project emitter (models, client, grouped operation traits, optional gentests/, and manifest).
    vigoo/openapi_to_moonbit/clinativeCLI argument parser, jailed local external $ref loader, filesystem writer, and drift checker.
    vigoo/openapi_to_moonbit/cmd/openapi_moonbitnativeExecutable CLI entry point (openapi-moonbit).

    #Features

    • OpenAPI 3.0 & 3.1 YAML and JSON specs, multi-spec merging (--spec repeatable), OpenAPI Overlays 1.0 (--overlay repeatable), and local/custom external $ref bundling.
    • Rich Schema Lowering: records with 4-state presence (Required, RequiredNullable, Optional, OptionalNullable, plus optional tri-state NullableField[T]), ergonomic Foo::new(req~, opt?) constructors, oneOf/anyOf discriminated & untagged unions, allOf inheritance/composition, OpenAPI 3.1 multi-type arrays, open/closed string enums, direction-aware readOnly/writeOnly request/response type splitting, and @rjson.DateTime (Eq + Compare).
    • Full Operation Support: path/query/header/cookie parameter styles, JSON, binary, text, application/x-www-form-urlencoded, and RFC 7578 multipart/form-data (with optional filenames), response headers, multi-status result enums, opt-in typed <Op>Error decoders (--emit-typed-errors), opt-in validate() methods (--emit-validators), HTTP streaming (SSE / NDJSON / chunked binary), WebSocket 101 upgrades, and server variable enums.
    • Generated Test Suites: --emit-tests generates a gentests/ package with schema example codec round-trips and mock-transport operation tests.
    • API-Surface Diffing: diff compares two specs and classifies Breaking vs NonBreaking changes (text or --json, with --fail-on-breaking for CI).

    #CLI Usage

    # Generate a client module openapi-moonbit generate \ --spec api.yaml \ --config client-config.yaml \ --out my_client # Merge multiple specs and apply overlays openapi-moonbit generate \ --spec core.yaml --spec billing.yaml \ --overlay fixups.overlay.yaml \ --out my_client --module acme/my_client # Verify generated files are up to date (CI drift check) openapi-moonbit check --spec api.yaml --config client-config.yaml --out my_client # Inspect schema and operation coverage openapi-moonbit inspect --spec api.yaml # Diff two specs for breaking API changes openapi-moonbit diff --old v1.yaml --new v2.yaml --fail-on-breaking

    #Common generate / check Flags

    • --spec <path> (repeatable) — OpenAPI 3.0/3.1 YAML or JSON input
    • --overlay <path> (repeatable) — OpenAPI Overlay 1.0 YAML or JSON patch
    • --config <path> — YAML GeneratorConfig file
    • --out <dir> — Output MoonBit module directory
    • --module <owner/name>, --version <ver>, --client-name <Name>, --error-name <Name>
    • --open-enums / --closed-enums, --open-unions / --closed-unions, --tri-state
    • --ignore-path <path_or_prefix*>, --global-tag <tag>, --format-override <FMT=TYPE>
    • --type-rename <Old=New>, --op-rename <opId=method>, --model-split-threshold <N>
    • --emit-tests, --emit-validators, --emit-typed-errors, --no-format, --lenient

    #YAML Configuration Reference

    module_name: acme/my_client module_version: "0.1.0" description: "Generated MoonBit client for Acme API." repository: "https://github.com/acme/my-client-moonbit" license: Apache-2.0 keywords: - acme - openapi - client default_base_url: "https://api.acme.example" runtime_package: "vigoo/openapi_client_runtime@0.1.0" x_package: "moonbitlang/x@0.5.9" client_name: Client error_name: ApiError open_string_enums: true open_tagged_unions: true tri_state: false model_split_threshold: 40 emit_tests: true emit_validators: false emit_typed_errors: false ignored_paths: - /internal/* global_tags: - UmbrellaService format_overrides: date-time: "@rjson.DateTime" type_renames: LegacyDto: Item operation_renames: getV1Items: list_items

    #Programmatic Sans-IO Pipeline

    The library facade (vigoo/openapi_to_moonbit) is pure/sans-IO and runs across native, js, wasm, and wasm-gc:

    ///|
    test "programmatic pipeline generates a complete client project" {
    let spec_yaml =
    #|openapi: "3.0.3"
    #|info:
    #| title: Pet API
    #| version: "1.0.0"
    #|paths:
    #| /pets:
    #| get:
    #| operationId: listPets
    #| tags: [Pets]
    #| responses:
    #| "200":
    #| description: ok
    #| content:
    #| application/json:
    #| schema:
    #| type: array
    #| items:
    #| type: string
    let project = @openapi_to_moonbit.Pipeline::from_yaml(spec_yaml)
    .with_config(
    @config.GeneratorConfig::default(module_name="acme/pet_client"),
    )
    .generate()
    assert_true(project.files.iter().any(f => f.path == "ops_pets.mbt"))
    assert_true(project.files.iter().any(f => f.path == "client.mbt"))
    }

    Pipeline

    pub struct Pipeline {
    // private fields
    }

    Fluent, sans-IO pipeline builder for programmatic OpenAPI → MoonBit client generation with overlays, multi-spec merging, external $ref bundling, IR transformation hooks, and file post-processing.

    Pipeline::build_ir

    Run parsing, bundling, merging, overlay application, IR lowering, and IR transformation hooks, returning (raw_combined_text, IrModel).

    Pipeline::from_json

    fn Pipeline::from_json(text : String) -> Pipeline

    Start a pipeline from an OpenAPI 3.0 / 3.1 JSON specification string.

    Pipeline::from_yaml

    fn Pipeline::from_yaml(text : String) -> Pipeline

    Start a pipeline from an OpenAPI 3.0 / 3.1 YAML specification string.

    Pipeline::generate

    Execute the full pipeline and return the generated MoonBit project.

    Pipeline::merge_json

    fn Pipeline::merge_json(self : Pipeline, text : String) -> Pipeline

    Merge an additional OpenAPI JSON spec into this pipeline.

    Pipeline::merge_yaml

    fn Pipeline::merge_yaml(self : Pipeline, text : String) -> Pipeline

    Merge an additional OpenAPI YAML spec into this pipeline.

    Pipeline::with_config

    Set the GeneratorConfig controlling module layout, naming, and codegen options.

    Pipeline::with_external_loader

    fn Pipeline::with_external_loader(self : Pipeline, base_uri? : String, loader : (String) -> String raise
    SpecError
    ) -> Pipeline

    Supply a sans-IO external $ref loader callback.

    Pipeline::with_ir_hooks

    Register IR transformation hooks applied after lowering and before code emission.

    Pipeline::with_mode

    Set the diagnostic severity mode (@spec.Strict or @spec.Lenient).

    Pipeline::with_overlay_json

    fn Pipeline::with_overlay_json(self : Pipeline, text : String) -> Pipeline

    Apply an OpenAPI Overlay 1.0 JSON document before decoding.

    Pipeline::with_overlay_yaml

    fn Pipeline::with_overlay_yaml(self : Pipeline, text : String) -> Pipeline

    Apply an OpenAPI Overlay 1.0 YAML document before decoding.

    Pipeline::with_post_process

    Register a post-processing callback to inspect or rewrite emitted GeneratedFiles.

    diff_ir

    Compare two IrModels and return classified breaking vs non-breaking changes.

    diff_specs

    Compare two OpenAPI YAML/JSON specs and return classified API-surface changes.

    generator_version

    fn generator_version() -> String

    Semantic version of the openapi_to_moonbit generator.

    inspect_report

    Render a human-readable OpenAPI construct coverage report.

    load_json

    Load an OpenAPI 3.0 / 3.1 JSON specification.

    load_yaml

    Load an OpenAPI 3.0 / 3.1 YAML specification.

    Source Files