cat_gateway/service/docs/
mod.rs

1//! Stoplight Elements `OpenAPI` UI
2#![allow(clippy::indexing_slicing)] // TODO: remove this when https://github.com/pyrossh/rust-embed/issues/243 is resolved positively
3
4mod stoplight_elements;
5use poem::{endpoint::EmbeddedFileEndpoint, get, Route};
6use poem_openapi::{OpenApi, OpenApiService, Webhook};
7use rust_embed::RustEmbed;
8
9/// Create the documentation pages where the `OpenAPI` docs can be viewed.
10pub(crate) fn docs<T, W>(api_service: &OpenApiService<T, W>) -> Route
11where
12    T: OpenApi + 'static,
13    W: Webhook + 'static,
14{
15    let swagger_ui = api_service.swagger_ui();
16    let rapidoc_ui = api_service.rapidoc();
17    let redoc_ui = api_service.redoc();
18    let openapi_explorer = api_service.openapi_explorer();
19    let stoplight_ui = stoplight_elements::create_endpoint(&api_service.spec());
20
21    Route::new()
22        .at("/", get(stoplight_ui))
23        .nest("/swagger_ui", swagger_ui)
24        .nest("/redoc", redoc_ui)
25        .nest("/rapidoc", rapidoc_ui)
26        .nest("/openapi_explorer", openapi_explorer)
27        .at("/cat-gateway.json", api_service.spec_endpoint())
28}
29
30/// Embed static files.
31#[derive(RustEmbed)]
32#[folder = "src/service/docs/files"]
33pub(crate) struct Files;
34
35/// Get an endpoint for favicon.ico
36pub(crate) fn favicon() -> Route {
37    Route::new().at("/", EmbeddedFileEndpoint::<Files>::new("favicon.ico"))
38}