swagger-ui-dist

Crates.ioswagger-ui-dist
lib.rsswagger-ui-dist
version
sourcesrc
created_at2024-05-19 19:49:27.436938
updated_at2025-01-01 17:00:47.318555
descriptionpackages the JS/CSS code of the swagger-ui in the form of axum routes
homepage
repositoryhttps://github.com/apimeister/swagger-ui-dist-rs/
max_upload_size
id1245175
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Jens Walter (JensWalter)

documentation

https://docs.rs/swagger-ui-dist

README

Latest Version

The version number reflects the swagger-ui version embedded.

Usage

With Inline OpenAPI

use axum::Router;
use swagger_ui_dist::{ApiDefinition, OpenApiSource};

#[tokio::main]
async fn main() {
    let api_def = ApiDefinition {
        uri_prefix: "/api",
        api_definition: OpenApiSource::Inline(include_str!("petstore.yaml")),
        title: Some("My Super Duper API"),
    };
    let app = Router::new().merge(swagger_ui_dist::generate_routes(api_def));
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    println!("listening on http://localhost:3000/api");
    axum::serve(listener, app).await.unwrap();
}

With external Route

use axum::{routing::get, Router};
use swagger_ui_dist::{ApiDefinition, OpenApiSource};

#[tokio::main]
async fn main() {
    let api_def = ApiDefinition {
        uri_prefix: "/api",
        api_definition: OpenApiSource::Uri("/openapi.yml"),
        title: Some("My Super Duper API"),
    };
    let app = Router::new()
        .route("/openapi.yml", get(|| async move { include_str!("petstore.yaml") }))
        .merge(swagger_ui_dist::generate_routes(api_def));
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    println!("listening on http://localhost:3000/api");
    axum::serve(listener, app).await.unwrap();
}

Supporting axum 0.7 and 0.8

Since axum 0.8 hase breaking changes, the crate supports both axum 0.7 and 0.8. By default, the crate uses the latest axum.

To use axum 0.7, add the following to your Cargo.toml:

[dependencies]
swagger-ui-dist = { version = "5.18.2", default-features = false, features = ["with-axum-07"] }

To use axum 0.8, add the following to your Cargo.toml:

[dependencies]
swagger-ui-dist = { version = "5.18.2" }
Commit count: 32

cargo fmt