openapi-gen-build (0.1.3)

Published 2026-07-25 11:48:15 +00:00 by clank-bot in Personal/my-rust-lib

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add openapi-gen-build@0.1.3 --registry forgejo

About this package

Build-time Rust client generation from OpenAPI specs via openapi-generator-cli

openapi-gen-build

Build-time Rust client generation from OpenAPI specs via openapi-generator-cli.

Usage

Add as a build dependency in Cargo.toml:

[build-dependencies]
openapi-gen-build = { path = "crates/openapi-gen-build" }

Then in build.rs:

use openapi_gen_build::Config;

fn main() {
    Config::new(std::env::var("OUT_DIR").unwrap().into())
        .spec("specs/api.yaml", "my_api")
        .generate()
        .emit_rerun_if_changed();
}

Generated modules are placed under crate::generated::<name> by default. Include them from your library:

mod generated;
// use generated::my_api::apis::...;

Configuration

Method Default Description
new(output_dir) Output directory (OUT_DIR)
.spec(input, name) Register an OpenAPI spec
.discover_specs(dir) Auto-discover *.json/*.yaml/*.yml in a directory
.namespace(ns) "crate::generated" Namespace prefix for generated modules
.generator(g) "rust" Generator language
.additional_property(k, v) Single --additional-properties entry
.additional_properties([...]) Bulk-set all additional properties
.allow_clippy(bool) true Prepend #![allow(clippy::all)] to generated .rs files
.generate() Run code generation
.emit_rerun_if_changed() Emit cargo:rerun-if-changed= instructions

Clippy

By default, #![allow(clippy::all)] is added to every generated file so that cargo clippy does not fail on generated code. Pass .allow_clippy(false) to opt out.

Namespace rewriting

Generated code references itself via crate::apis:: and crate::models::. When the module tree is nested, these paths are rewritten to use the configured namespace prefix so imports resolve correctly.

License

MIT

Details
Cargo
2026-07-25 11:48:15 +00:00
89
MIT
6.7 KiB
Assets (1)
Versions (5) View all
0.1.4 2026-08-01
0.1.3 2026-07-25
0.1.2 2026-07-25
0.1.1 2026-07-25
0.1.0 2026-07-24