#openapi #swagger #documentation #openapi-documentation

scalar-doc

An HTTP API documentation generator for Rust that doesn't care about which HTTP framework you use

3 releases

0.1.2 Jun 17, 2025
0.1.1 May 18, 2025
0.1.0 Aug 27, 2024

#641 in HTTP server

Download history 162/week @ 2025-06-17 99/week @ 2025-06-24 148/week @ 2025-07-01 78/week @ 2025-07-08 98/week @ 2025-07-15 121/week @ 2025-07-22 79/week @ 2025-07-29 105/week @ 2025-08-05 89/week @ 2025-08-12 103/week @ 2025-08-19 45/week @ 2025-08-26 92/week @ 2025-09-02 184/week @ 2025-09-09 127/week @ 2025-09-16 30/week @ 2025-09-23 70/week @ 2025-09-30

443 downloads per month
Used in skillet

Apache-2.0

17KB
193 lines

Scalar Doc (for Rust)

An HTTP API documentation generator for Rust that doesn't care about which HTTP framework you use.

Using scalar !!!

Usage

To use this crate, add it to your Cargo.toml with :

cargo add scalar_doc

Also, you will need to expose your OpenAPI schema as an HTTP endpoint since it's too complicated to find the path of the schema file (it's an open issue though so I would be really happy if you contribute it).

Axum

use axum::{routing::get, Router};
use scalar_doc::Documentation;

async fn doc() -> String {
    Documentation::new("Api Documentation title", "/openapi")
        .favicon("/favicon.svg", FaviconMimeType::Svg)
        .build()
        .unwrap()
}

async fn openapi() -> &'static str {
    include_str!("openapi.json")
}

#[tokio::main]
async fn main() {
    println!("Hello, world!");
    let app = Router::new()
        .route("/", get(doc))
        .route("/openapi", get(openapi));

    let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();

    axum::serve(listener, app).await.unwrap();
}

Actix

To use scalar-doc with actix, you will need to activate the actix feature in your Cargo.toml file.

cargo add scalar-doc -F actix
use actix_web::{get, App, HttpResponse, HttpServer, Responder};
use scalar_doc::{favicon::FaviconMimeType, scalar_actix::ActixDocumentation};

#[get("/")]
async fn doc() -> impl Responder {
    ActixDocumentation::new("Api Documentation title", "/openapi")
        .favicon("/favicon.svg", FaviconMimeType::Svg)
        .theme(scalar_doc::Theme::Kepler)
        .service()
}

#[get("/openapi")]
async fn openapi() -> impl Responder {
    let open = include_str!("openapi.json");
    HttpResponse::Ok().body(open)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(doc).service(openapi))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
}

Check out the examples for more show cases.

Contributors

Courtcircuits
Courtcircuits
theotchlx
theotchlx
dcdms
dcdms
smokingplaya
smokingplaya

Dependencies

~7–21MB
~288K SLoC