Files
biggus-dickus/crates/api/src/openapi.rs
T

31 lines
929 B
Rust

use axum::{Json, Router, extract::State, routing::get};
use utoipa::OpenApi;
use crate::{AppState, health, public};
#[derive(OpenApi)]
#[openapi(
paths(health::live, health::ready, public::list_objects, public::get_object),
components(schemas(
health::Live,
health::Ready,
public::PublicView,
public::PublicObjectPage
)),
info(title = "Collection Management System", version = "0.0.0")
)]
struct ApiDoc;
/// Serve the OpenAPI document, overriding the title from runtime config so the
/// product name is never hardcoded.
async fn openapi_json(State(state): State<AppState>) -> Json<utoipa::openapi::OpenApi> {
let mut doc = ApiDoc::openapi();
doc.info.title = state.app_name.clone();
Json(doc)
}
/// OpenAPI routes, parameterized over [`AppState`].
pub(crate) fn routes() -> Router<AppState> {
Router::new().route("/api-docs/openapi.json", get(openapi_json))
}