Expand description
This crate implements necessary boiler plate 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 boiler plate for:
- actix-web
version >= 4 - rocket
version >=0.5.0-rc.3 - axum
version >=0.6
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 bit more manual implementation to be done. See
more details at serve or examples.
§Crate Features
- actix-web Enables
actix-webintegration with pre-configured SwaggerUI service factory allowing users to use the Swagger UI without a hassle. - rocket Enables
rocketintegration with with pre-configured routes for serving the Swagger UI and api doc without a hassle. - axum Enables
axumintegration with pre-configured Router serving Swagger UI and OpenAPI specs hassle free. - debug-embed Enables
debug-embedfeature onrust_embedcrate to allow embedding files in debug builds as well.
§Install
Use only the raw types without any boiler plate implementation.
[dependencies]
utoipa-swagger-ui = "3"Enable actix-web framework with Swagger UI you could define the dependency as follows.
[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.
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.
#[rocket::launch]
fn rocket() -> Rocket<Build> {
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.
let app = Router::<S, B>::new()
.merge(SwaggerUi::new("/swagger-ui")
.url("/api-docs/openapi.json", ApiDoc::openapi()));Modules§
- oauth
- Implements Swagger UI oauth configuration options.
Structs§
- Config
- Object used to alter Swagger UI settings.
- Swagger
File - Represents servable file of Swagger UI. This is used together with
servefunction to serve Swagger UI files via web server. - Swagger
Ui - Entry point for serving Swagger UI and api docs in application. It uses provides builder style chainable configuration methods for configuring api doc urls.
- Url
- Rust type for Swagger UI url configuration object.
Functions§
- serve
- User friendly way to serve Swagger UI and its content via web server.