utoipa
Compile-time generated OpenAPI documentation for Rust APIs
Repository Health
Technical Analysis
utoipa generates OpenAPI 3.1 specifications directly from Rust source code at compile time, using derive macros on your existing structs and handler functions instead of a separate annotation DSL or runtime reflection. It integrates with popular Rust web frameworks including Actix Web, Axum, and Rocket, so route signatures and types become the single source of truth for the API schema.
Beyond raw spec generation, the workspace ships companion crates for serving interactive documentation UIs — Swagger UI, Redoc, RapiDoc, and Scalar — directly from the generated spec, and a config crate for customizing output, making it a complete compile-time OpenAPI toolchain rather than just a schema generator.
What You Get
- Derive macros (
ToSchema,#[utoipa::path],OpenApi) that generate OpenAPI 3.1 specs from existing Rust types and handlers - Framework integration crates (
utoipa-axum,utoipa-actix-web) that wire routes directly into the generated spec - Bundled documentation UI crates:
utoipa-swagger-ui,utoipa-redoc,utoipa-rapidoc,utoipa-scalar - A
utoipa-configcrate for customizing generation behavior without hand-editing macro output - Compile-time validation, so schema/route mismatches surface as build errors rather than runtime failures
Common Use Cases
- Documenting a Rust REST API built with Actix Web or Axum without maintaining a hand-written OpenAPI YAML file
- Serving an interactive Swagger UI or Scalar docs page directly from a Rust web service
- Generating client-consumable OpenAPI specs as part of a CI pipeline for downstream SDK generation
- Keeping API documentation in sync with code by deriving schemas from the same structs used at runtime
Under The Hood
Architecture utoipa is a Cargo workspace of ten member crates: the core utoipa crate defines the public traits/types (ToSchema, OpenApi) that the generated spec conforms to, utoipa-gen implements the proc-macros that do the actual compile-time code generation, and separate crates (utoipa-axum, utoipa-actix-web) adapt the generated spec to each web framework’s routing conventions, while utoipa-swagger-ui/-redoc/-rapidoc/-scalar each vendor a documentation UI and serve it from the spec. Tech Stack Pure Rust workspace (edition 2021, rust-version 1.88+) resolved with Cargo’s resolver v2; the proc-macro-heavy utoipa-gen crate is the most complex member at roughly 10k lines across the core utoipa crate’s source, with utoipa-swagger-ui-vendored bundling the Swagger UI static assets so no network fetch is needed at build or run time. Code Quality utoipa-gen/tests/ contains dedicated derive-macro test suites (openapi_derive_test.rs, path_derive_axum_test.rs, path_parameter_derive_test.rs) plus a testdata fixture directory, and workspace-level Clippy lints are enforced (including a guard against large stack allocations in generated code, tracked against a real regression issue) — indicating active attention to both correctness and generated-code efficiency. API Design The library favors deriving documentation from types Rust code already has (#[derive(ToSchema)] on existing structs, #[utoipa::path] on existing handlers) rather than requiring a parallel schema DSL, so adopting it in an existing Actix/Axum service is largely additive rather than a rewrite.
Used by 13 apps in this directory
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.