Requirements
You need a Rust toolchain with Rust 1.88 or newer and an OpenAPI 3.0 or 3.1 document in YAML or JSON. Experimental OpenAPI 3.2 parsing is available, but you should review theschema support notes before relying on newer fields.
openapi-to-rust is spec-first: it generates Rust from an existing OpenAPI contract. If you want to generate an OpenAPI document from Rust source, use a code-first library such as Utoipa or Aide instead.
Install the Cargo CLI
Install the published crate with its lockfile so Cargo uses the dependency versions tested for the release:
cargo install --locked openapi-to-rust
openapi-to-rust --versionCargo compiles the CLI locally. There are currently no prebuilt binaries, so a working Rust toolchain is required. You do not need Java, Node.js, or Docker to run the generator.
Generate code from an OpenAPI document
For a quick trial, generate from the project’s stable hosted fixture:
openapi-to-rust generate \
https://raw.githubusercontent.com/gpu-cli/openapi-to-rust/v0.6.0/tests/fixtures/operation_extraction/simple_get.jsonFor your own project, pass a local YAML or JSON file:
openapi-to-rust generate openapi.yamlThe async client is generated by default. Use --types-only if you only need Serde models,--dry-run to inspect the generation plan without writing, or --check to detect stale output.
Understand the generated files
The default command writes a self-contained module under src/generated:
| File | Purpose |
|---|---|
types.rs | Serde structs and enums derived from schemas and inline operation types. |
client.rs | Async Reqwest methods, request serialization, auth hooks, and typed operation errors. |
mod.rs | Module exports for the generated surface. |
REQUIRED_DEPS.toml | The exact dependencies needed to compile this particular output. |
Streaming or server files appear only when those features are configured. Generated output is designed to be committed so application builds do not need to fetch the API document or execute code generation.
Create a reusable configuration
Initialize a TOML file, then generate using its defaults:
openapi-to-rust init openapi.yaml
openapi-to-rust generate[generator]
spec_path = "openapi.yaml"
output_dir = "src/generated"
module_name = "api"
[features]
enable_async_client = true
[http_client]
base_url = "https://api.example.com"
timeout_seconds = 30Relative paths are resolved from the TOML file rather than the shell’s working directory. That makes the same command reliable from a developer laptop, a workspace root, or CI.
HTTPS documents are supported directly. Remote fetches reject embedded credentials and redirects, enforce time and size limits, and allow plain HTTP only for loopback development. For reproducible releases, prefer a versioned URL or a checked-in document.
Keep generated Rust current in CI
Commit the generated module and add a check that reruns analysis without overwriting files. A non-zero exit tells you the OpenAPI document, configuration, or generated Rust has drifted.
openapi-to-rust generate --check --quiet
cargo check
--checkverifies freshness. It does not replacecargo check, which proves that the generated module compiles with your project’s dependency choices.
Choose your next path
- Configure the Rust client generator for selected operations, auth, retries, tracing, builders, and typed errors.
- Generate an Axum server from OpenAPI when you are implementing the contract rather than consuming it.
- Review compatibility evidence for real-world specs and current conformance boundaries.