OpenAPI · TypeSpec → Axum
crabspec turns an OpenAPI 3.0/3.1 document or a TypeSpec design into an idiomatic Axum server. You write one plain async fn per operation. It writes the routing, parsing, validation and typed responses.
$ crabspec generate openapi.yaml -o src/api --module
model Pet { @visibility(Lifecycle.Read) id: uuid; @minLength(1) name: string; owner?: Owner; } @route("/pets/{petId}") op read( @path petId: uuid ): Pet | NotFound;
impl PetsApi for PetStore { async fn read(&self, req: PetsReadRequest) -> Result<PetsReadResponse, Error> { // req.pet_id is already a validated uuid match self.db.find(req.pet_id).await? { Some(pet) => Ok(PetsReadResponse::Ok(pet)), None => Ok(PetsReadResponse::NotFound(..)), } } }
Save CPUs. Sam needs them for GPUs.
On the same spec, OpenAPI Generator's rust-axum server burns 2.6× the CPU per request. crabspec's generated server runs level with hand-written Axum, and still validates every request.
Petstore, the same in-memory logic in all three servers. CPU time per 100,000 requests: shorter is better.
rust-axum 7.28.0oha with 64 connections for 8 s per endpoint, averaged over GET /pets, GET /pets/{id} and POST /pets, on Apple Silicon with the load generator on the same machine. All requests returned 2xx; expect a few percent of run-to-run noise. crabspec doesn't hop to a blocking thread pool twice per request or run an HTML sanitizer over every string. Reproduce it with bench/setup.sh and bench/run-bench.sh in the repo.
We ran real specs through OpenAPI Generator's rust-axum: a TypeSpec design, OpenAI's 406-operation API, and a small spec of known edge cases. Every crabspec result below has a test in the repo.
| Input | rust-axum 7.28.0 | crabspec |
|---|---|---|
| OpenAI's API spec (406 ops, OAS 3.1) | 535k lines, 62 compile errors | 185k lines, compiles |
Versioned TypeSpec API (2026-06-01) | Invalid Cargo.toml | Compiles |
Recursive types (Dog.bestFriend: Dog) | Infinite-size type error | Option<Box<Dog>>, only where needed |
POST /pets without the read-only id | Rejected: missing field id | Accepted; PetInput has no id |
A Cat posted as a Pet | Silently becomes {"kind":"Pet"}, indoor dropped | Pet::Cat(Cat), round-trips exactly |
Integer enum size: 2 | Rejected: expects the string "2" | 2 |
"Tom <3" as a name | Rejected as "XSS" | It's a name |
| Handler signature | async_trait, plus &Method, &Host, &CookieJar on every call | async fn list(&self, request: PetsListRequest) |
The generated code depends only on axum, serde and serde_json, is formatted, and is documented from your spec's descriptions.
allOf + discriminator becomes enum Pet { Cat(Cat), Dog(Dog) }.oneOf/anyOf become tagged or untagged enums.readOnly/writeOnly get separate …Input types.Option<Option<T>>.uint8.pattern with exact ECMAScript semantics, compiled once.date-time, date, time and uuid formats.body.owner.name.Security trait.request.auth.WWW-Authenticate, 403 for missing scopes.501, so a 70-operation API compiles before you write a handler.Interface_operation ids become interface.operation().Ok, Created { body, location }, NotFound(ApiError).async_trait, no boxed futures.crabspec generate --check fails CI when generated code is stale.router() returns a plain axum::Router: your tower layers attach as usual.crabspec is on GitHub now; a crates.io release is coming soon.
cargo install --git \ https://github.com/Wolg/crabspec crabspec
# from TypeSpec
npx tsp compile .
crabspec generate \
tsp-output/@typespec/openapi3/openapi.yaml \
-o src/api --modulelet app = router(Arc::new(PetStore::new())); axum::serve(listener, app).await?;
Expect breaking changes. A spec that breaks crabspec is the best bug report.
Bytes.Strings, not chrono/uuid types; email and uri aren't checked.-D warnings on every change.