#utoipa #actix-web #bindings #generate

utoipa-actix-web

Utoipa's actix-web bindings for seamless integration of the two

3 releases

0.1.2 Nov 8, 2024
0.1.1 Oct 30, 2024
0.1.0 Oct 23, 2024

#1769 in Web programming

Download history 70/week @ 2024-10-17 186/week @ 2024-10-24 470/week @ 2024-10-31 781/week @ 2024-11-07 613/week @ 2024-11-14

2,120 downloads per month
Used in mehari

MIT/Apache

410KB
6.5K SLoC

utoipa-actix-web - Bindings for Actix Web and utoipa

Utoipa build crates.io docs.rs rustc

This crate implements necessary bindings for automatically collecting paths and schemas recursively from Actix Web App, Scope and ServiceConfig. It provides natural API reducing duplication and support for scopes while generating OpenAPI specification without the need to declare paths and schemas to #[openapi(...)] attribute of OpenApi derive.

Currently only service(...) calls supports automatic collection of schemas and paths. Manual routes via route(...) or Route::new().to(...) is not supported.

Install

Add dependency declaration to Cargo.toml.

[dependencies]
utoipa-actix-web = "0.1"

Examples

Collect handlers annotated with #[utoipa::path] recursively from service(...) calls to compose OpenAPI spec.

use actix_web::{get, App};
use utoipa_actix_web::{scope, AppExt};

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

#[utoipa::path(responses((status = OK, body = User)))]
#[get("/user")]
async fn get_user() -> Json<User> {
    Json(User { id: 1 })
}

let (_, mut api) = App::new()
    .into_utoipa_app()
    .service(scope::scope("/api/v1").service(get_user))
    .split_for_parts();

License

Licensed under either of Apache 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be dual licensed, without any additional terms or conditions.

Dependencies

~16–27MB
~447K SLoC