OpenAPI generator for Rust
Generate Rust clients and Axum servers from OpenAPI.
openapi-to-rust turns OpenAPI 3.0 and 3.1 documents into shared Serde
models, selected Reqwest methods, typed API errors, SSE streams, and Axum traits.
CI generates all 54 specs on every pull request; OpenAI and Anthropic outputs also compile.
What CI verifies.
Every pull request runs the generator over 54 supported documents. OpenAI and Anthropic
generated crates also run cargo check with exact dependencies. The scheduled
and manual tier is configured to compile all 54. One Swagger 2.0 document is skipped.
This establishes parse, generation, and compile coverage—not behavior against a live API.
# Every pull request
SPEC_COMPILE_PARSE_ONLY=1 scripts/spec-compile.sh
scripts/spec-compile.sh anthropic openai
# Scheduled and manual CI
scripts/spec-compile.sh
Every pull request54 generate · OpenAI + Anthropic cargo checkactive
Scheduled / manualAll 54 run cargo checkconfigured
Inspect the generated Rust.
This enum comes from the checked-in discriminator fixture. The repository also includes a generated Reqwest client and a compiled Axum implementation for OpenAI’s Responses API.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum ToolResultCaller {
#[serde(rename = "direct")]
DirectCaller(DirectCaller),
#[serde(rename = "server")]
ServerCaller(ServerCaller),
}
Generate only the operations you use.
Select an exact operationId, METHOD /path, or tag:name.
Optional pruning keeps schemas reachable from the selected client and server operations.
- Shared models
- One
types.rsfor request and response shapes on both sides. - Reqwest client
- Async methods, auth, typed responses and errors, retries, tracing, and SSE.
- Axum server
- Per-tag traits, response enums, parameter extraction, routing, and SSE responses.
Commit generated code. Fail CI when it drifts.
--check exits nonzero when committed output no longer matches the OpenAPI document
or configuration. Use --dry-run to inspect the generation plan without writing files.
openapi-to-rust generate openapi.yaml --check --quiet
cargo check
Before you adopt it.
openapi-to-rust is intentionally Rust-only. If you need many target languages, compare it with OpenAPI Generator’s separate Rust client and Rust Axum server generators.
Compare features and tradeoffsWhat does this OpenAPI generator for Rust emit?
Shared Serde models, selected async Reqwest methods, typed API errors, optional SSE streams, and selected Axum traits and routes.
Which OpenAPI versions are supported?
OpenAPI 3.0 and 3.1 are supported. OpenAPI 3.2 parsing is experimental. Swagger 2.0 documents are not accepted.
Does generated code validate every schema constraint at runtime?
No. Minimums, maximums, and patterns are emitted as Rust documentation rather than runtime validators.
Start with your spec.
cargo install --locked openapi-to-rust