utoipa

Compile-time generated OpenAPI documentation for Rust APIs

Library
Cargo
v5.5.0
4,033stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity80
Maintenance88
Community72
Maturity56
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality84
Innovation80
Learning Curve74

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-config crate 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search