#swagger-ui #open-api #axum #routes #forms

swagger-ui-dist

packages the JS/CSS code of the swagger-ui in the form of axum routes

5 stable releases

new 5.18.2 Dec 4, 2024
5.17.14 May 28, 2024
5.17.13 May 27, 2024
5.17.12 May 21, 2024
5.17.10 May 19, 2024

#1166 in HTTP server

Download history 180/week @ 2024-08-17 187/week @ 2024-08-24 114/week @ 2024-08-31 97/week @ 2024-09-07 87/week @ 2024-09-14 138/week @ 2024-09-21 64/week @ 2024-09-28 41/week @ 2024-10-05 138/week @ 2024-10-12 78/week @ 2024-10-19 81/week @ 2024-10-26 102/week @ 2024-11-02 54/week @ 2024-11-09 45/week @ 2024-11-16 79/week @ 2024-11-23 315/week @ 2024-11-30

508 downloads per month

Apache-2.0

4MB
122 lines

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();
}

Dependencies

~5–11MB
~124K SLoC