openapi-gen-build (0.1.3)
Installation
[registries.forgejo]
index = "sparse+ " # Sparse index
# index = " " # Git
[net]
git-fetch-with-cli = truecargo add openapi-gen-build@0.1.3 --registry forgejoAbout 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
Assets (1)
Versions (5)
View all
openapi-gen-build-0.1.3.crate
6.7 KiB