Skip to content
Clone
caf6766
44 lines 1.2 KB Rust
use crate::{health, router::API_PREFIX};
use axum::http::{Response, StatusCode};
use once_cell::sync::Lazy;
use utoipa::{Modify, OpenApi};
use utoipa_scalar::{Scalar, Servable};
#[derive(OpenApi)]
#[openapi(
info(
title = "Untitled API",
description = "Unified HTTP API for the untitled platform",
version = "1.94.0"
),
paths(health::liveness, health::readiness)
)]
struct WebapiApiDoc;
pub fn openapi() -> utoipa::openapi::OpenApi {
let mut doc = export::openapi_concat!(
WebapiApiDoc,
auth::handler::AuthApiDoc,
issues::IssuesApiDoc,
post::PostsApiDoc,
project::ProjectApiDoc,
repo::handler::openapi::ApiDoc,
space::SpaceApiDoc,
user::UserApiDoc
);
export::openapi::PrefixModifier {
prefix: API_PREFIX.to_owned(),
}
.modify(&mut doc);
doc
}
static DOCS_HTML: Lazy<String> = Lazy::new(|| Scalar::with_url("/api-docs", openapi()).to_html());
pub async fn docs() -> Response<String> {
Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "text/html")
.body(DOCS_HTML.clone())
.expect("Failed to build response")
}