Crate utoipa_axum

Source
Expand description

Utoipa axum brings utoipa and axum closer together by the way of providing an ergonomic API that is extending on the axum API. It gives a natural way to register handlers known to axum and also simultaneously generates OpenAPI specification from the handlers.

§Crate features

  • debug: Implement debug traits for types.

§Install

Add dependency declaration to Cargo.toml.

[dependencies]
utoipa-axum = "0.1"

§Examples

Use OpenApiRouter to collect handlers with #[utoipa::path] macro to compose service and form OpenAPI spec.

 #[derive(utoipa::ToSchema, serde::Serialize)]
 struct User {
     id: i32,
 }

 #[utoipa::path(get, path = "/user", responses((status = OK, body = User)))]
 async fn get_user() -> Json<User> {
    Json(User { id: 1 })
 }
  
 let (router, api): (axum::Router, OpenApi) = OpenApiRouter::new()
     .routes(routes!(get_user))
     .split_for_parts();

Modules§

  • Implements Router for composing handlers and collecting OpenAPI information.

Macros§

Traits§