utoipa-swagger-ui

Utoipa build crates.io docs.rs rustc

This crate implements necessary boilerplate code to serve Swagger UI via web server. It works as a bridge for serving the OpenAPI documentation created with utoipa library in the Swagger UI.

Currently implemented boilerplate for:

Serving Swagger UI is framework independent thus this crate also supports serving the Swagger UI with other frameworks as well. With other frameworks, there is a bit more manual implementation to be done. See more details at serve or examples.

Crate Features

Install

Use only the raw types without any boilerplate implementation. toml [dependencies] utoipa-swagger-ui = "3"

Enable actix-web framework with Swagger UI you could define the dependency as follows. toml [dependencies] utoipa-swagger-ui = { version = "3", features = ["actix-web"] }

Note! Also remember that you already have defined utoipa dependency in your Cargo.toml

Examples

Serve Swagger UI with api doc via actix-web. See full example from examples. rust HttpServer::new(move || { App::new() .service( SwaggerUi::new("/swagger-ui/{_:.*}") .url("/api-docs/openapi.json", ApiDoc::openapi()), ) }) .bind((Ipv4Addr::UNSPECIFIED, 8989)).unwrap() .run();

Serve Swagger UI with api doc via rocket. See full example from examples. ```rust

[rocket::launch]

fn rocket() -> Rocket { rocket::build() .mount( "/", SwaggerUi::new("/swagger-ui/<_..>") .url("/api-docs/openapi.json", ApiDoc::openapi()), ) } ```

Setup Router to serve Swagger UI with axum framework. See full implementation of how to serve Swagger UI with axum from examples. rust let app = Router::new() .merge(SwaggerUi::new("/swagger-ui") .url("/api-docs/openapi.json", ApiDoc::openapi()));

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.