How to Use OpenAPI/Swagger with Rust (utoipa)

Web
Generate OpenAPI docs for Axum apps using the aide crate with simple annotations and routing.

Use the aide crate to generate OpenAPI documentation for your Axum application by adding it to your dependencies and annotating your handlers.

[dependencies]
axum = "0.7"
aide = { version = "0.12", features = ["axum"] }
use axum::routing::get;
use aide::axum::ApiRouter;
use aide::openapi::Info;

#[utoipa::path(get, path = "/", responses(Ok = String))]
async fn hello() -> &'static str {
    "Hello, World!"
}

#[tokio::main]
async fn main() {
    let app = ApiRouter::new()
        .info(Info::new("My API", "1.0.0"))
        .route("/", get(hello));

    // Run app with axum::serve
}