52 lines
1.4 KiB
Rust

use std::sync::Arc;
use axum::{
Router,
http::{HeaderValue, StatusCode},
response::{Html, IntoResponse, Response},
routing::get,
};
use super::AppState;
static OPENAPI_JSON: &'static str = include_str!("../../openapi.json");
static SCALAR_DOCS: &'static str = include_str!("./docs/scalar.html");
static SWAGGER_DOCS: &'static str = include_str!("./docs/swagger.html");
static RAPIDOC_DOCS: &'static str = include_str!("./docs/rapidoc.html");
static INDEX: &'static str = include_str!("./docs/index.html");
pub(super) fn router() -> Router<Arc<AppState>> {
Router::new()
.route("/", get(index_html))
.route("/openapi.json", get(openapi_json))
.route("/scalar", get(scalar_html))
.route("/swagger", get(swagger_html))
.route("/rapidoc", get(rapidoc_html))
}
fn with_content_type(body: &'static str, content_type: &'static str) -> Response {
let mut response = (StatusCode::OK, body).into_response();
response
.headers_mut()
.insert("Content-Type", HeaderValue::from_static(content_type));
response
}
async fn openapi_json() -> Response {
with_content_type(OPENAPI_JSON, "application/json")
}
async fn scalar_html() -> Html<&'static str> {
Html(SCALAR_DOCS)
}
async fn swagger_html() -> Html<&'static str> {
Html(SWAGGER_DOCS)
}
async fn rapidoc_html() -> Html<&'static str> {
Html(RAPIDOC_DOCS)
}
async fn index_html() -> Html<&'static str> {
Html(INDEX)
}