utoipa-redoc
This crate works as a bridge between utoipa and Redoc OpenAPI visualizer.
Utoipa-redoc 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
Redocviaactix-web.version >= 4 - rocket Allows serving
Redocviarocket.version >=0.5 - axum Allows serving
Redocviaaxum.version >=0.7
Install
Use Redoc only without any boiler plate implementation.
[]
= "3"
Enable actix-web integration with Redoc.
[]
= { = "3", = ["actix-web"] }
Using standalone
Utoipa-redoc can be used standalone as simply as creating a new Redoc instance and then
serving it by what ever means available as text/html from http handler in your favourite web
framework.
Redoc::to_html method can be used to convert the Redoc instance to a servable html
file.
let redoc = new;
// Then somewhere in your application that handles http operation.
// Make sure you return correct content type `text/html`.
let redoc_handler = move || async ;
Customization
Utoipa-redoc enables full customizaton support for Redoc according to what can be customized by modifying the HTML template and configuration options.
The default HTML template can be fully overridden to ones liking with
Redoc::custom_html method. The HTML template must contain $spec and $config
variables which are replaced during Redoc::to_html execution.
$specWill be theSpecthat will be rendered via Redoc.$configWill be the currentConfig. By default this isEmptyConfig.
Overiding the HTML template with a custom one.
let html = "...";
new.custom_html;
Configuration
Redoc can be configured with JSON either inlined with the Redoc declaration or loaded from
user defined file with FileConfig.
Inlining the configuration.
with_config;
Using FileConfig.
with_config;
Read more details in Config.
Examples
Serve Redoc via actix-web framework.
use App;
use ;
new.service;
Serve Redoc via rocket framework.
use ;
build
.mount;
Serve Redoc via axum framework.
use Router;
use ;
let app = new
.merge;
Use Redoc to serve OpenAPI spec from url.
new
Use Redoc to serve custom OpenAPI spec using serde's json!() macro.
new;
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.