4 releases

0.2.0-rc.0 Oct 2, 2024
0.2.0-beta.0 Sep 1, 2024
0.2.0-alpha.0 May 30, 2024
0.1.0 May 5, 2024

#1848 in Web programming

Download history 678/week @ 2024-06-20 1047/week @ 2024-06-27 1308/week @ 2024-07-04 1283/week @ 2024-07-11 1411/week @ 2024-07-18 1611/week @ 2024-07-25 1400/week @ 2024-08-01 1565/week @ 2024-08-08 1194/week @ 2024-08-15 1742/week @ 2024-08-22 1832/week @ 2024-08-29 2103/week @ 2024-09-05 1938/week @ 2024-09-12 3507/week @ 2024-09-19 4459/week @ 2024-09-26 3576/week @ 2024-10-03

13,885 downloads per month
Used in 6 crates (4 directly)

MIT/Apache

365KB
5.5K SLoC

utoipa-scalar

Utoipa build crates.io docs.rs rustc

This crate works as a bridge between utoipa and Scalar OpenAPI visualizer.

Utoipa-scalar provides simple mechanism to transform OpenAPI spec resource to a servable HTML file which can be served via predefined framework integration or used standalone and served manually.

You may find fullsize examples from utoipa's Github repository.

Crate Features

  • actix-web Allows serving Scalar via actix-web. version >= 4
  • rocket Allows serving Scalar via rocket. version >=0.5
  • axum Allows serving Scalar via axum. version >=0.7

Install

Use Scalar only without any boiler plate implementation.

[dependencies]
utoipa-scalar = "0.1"

Enable actix-web integration with Scalar.

[dependencies]
utoipa-scalar = { version = "0.1", features = ["actix-web"] }

Using standalone

Utoipa-scalar can be used standalone as simply as creating a new Scalar instance and then serving it by what ever means available as text/html from http handler in your favourite web framework.

Scalar::to_html method can be used to convert the Scalar instance to a servable html file.

let scalar = Scalar::new(ApiDoc::openapi());

// Then somewhere in your application that handles http operation.
// Make sure you return correct content type `text/html`.
let scalar = move || async {
    scalar.to_html()
};

Examples

Serve Scalar via actix-web framework.

use actix_web::App;
use utoipa_scalar::{Scalar, Servable};

App::new().service(Scalar::with_url("/scalar", ApiDoc::openapi()));

Serve Scalar via rocket framework.

use utoipa_scalar::{Scalar, Servable};

rocket::build()
    .mount(
        "/",
        Scalar::with_url("/scalar", ApiDoc::openapi()),
    );

Serve Scalar via axum framework.

use axum::Router;
use utoipa_scalar::{Scalar, Servable};

let app = Router::<S>::new()
    .merge(Scalar::with_url("/scalar", ApiDoc::openapi()));

Use Scalar to serve OpenAPI spec from url.

Scalar::new(
  "https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml")

Use Scalar to serve custom OpenAPI spec using serde's json!() macro.

Scalar::new(json!({"openapi": "3.1.0"}));

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.

Dependencies

~1–34MB
~535K SLoC