OpenAPI ↔ Rust. This is one compiler in a suite, all focussed on the same task: Compiler Driven Development (CDD).
Each compiler is written in its target language, is whitespace and comment sensitive, and has both an SDK and CLI.
The CLI—at a minimum—has:
cdd-rust --helpcdd-rust --versioncdd-rust from_openapi to_sdk_cli -i spec.jsoncdd-rust from_openapi to_sdk -i spec.jsoncdd-rust from_openapi to_server -i spec.jsoncdd-rust to_openapi -f path/to/codecdd-rust to_docs_json --no-imports --no-wrapping -i spec.jsoncdd-rust serve_json_rpc --port 8080 --listen 0.0.0.0
The goal of this project is to enable rapid application development without tradeoffs. Tradeoffs of Protocol Buffers / Thrift etc. are an untouchable "generated" directory and package, compile-time and/or runtime overhead. Tradeoffs of Java or JavaScript for everything are: overhead in hardware access, offline mode, ML inefficiency, and more. And neither of these alternative approaches are truly integrated into your target system, test frameworks, and bigger abstractions you build in your app. Tradeoffs in CDD are code duplication (but CDD handles the synchronisation for you).
The cdd-rust compiler leverages a unified architecture to support various facets of API and code lifecycle management.
- Compilation:
- OpenAPI →
Rust: Generate idiomatic native models, network routes, client SDKs, and boilerplate directly from OpenAPI (.json/.yaml) specifications. Rust→ OpenAPI: Statically parse existingRustsource code and emit compliant OpenAPI specifications.
- OpenAPI →
- AST-Driven & Safe: Employs static analysis instead of unsafe dynamic execution or reflection, allowing it to safely parse and emit code even for incomplete or un-compilable project states.
- Seamless Sync: Keep your docs, tests, database, clients, and routing in perfect harmony. Update your code, and generate the docs; or update the docs, and generate the code.
cargo build
cargo testYou can also use the included cross-platform Makefiles to fetch dependencies, build, and test:
# Install dependencies
make deps
# Build the project
make build
# Run tests
make test# Generate Rust models from an OpenAPI spec
cdd-rust from_openapi to_sdk -i spec.json -o src/models
# Generate an OpenAPI spec from your Rust code
cdd-rust to_openapi -f src/models -o openapi.jsonuse cdd_core::openapi::parse::parse_openapi_spec;
use cdd_core::classes::emit::generate_dtos;
use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let spec = fs::read_to_string("spec.yaml")?;
let models = parse_openapi_spec(&spec)?;
// Generate idiomatic Rust structs from the OpenAPI Components/Schemas
let rust_code = generate_dtos(&models);
fs::write("models.rs", rust_code)?;
Ok(())
}(The boxes below reflect the features supported by this specific cdd-rust implementation)
| Features | Parse (From) | Emit (To) |
|---|---|---|
| OpenAPI 3.2.0 | ✅ | ✅ |
| API Client SDK | ✅ | ✅ |
| API Client CLI | ✅ | ✅ |
| Server Routes / Endpoints | ✅ | ✅ |
| ORM / DB Schema | [ ] | [ ] |
| Mocks + Tests | [ ] | [ ] |
| Model Context Protocol (MCP) | [ ] | [ ] |
cdd-rust supports extensive backwards compatibility features:
- Legacy Swagger 2.0 Support: Natively parses and processes legacy
swagger: "2.0"specifications in addition to OpenAPI 3.x, ensuring seamless backwards compatibility and bridging older APIs into the modern Rust ecosystem.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.