feat(api): add health probes, OpenAPI doc, and router
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
use axum::{Json, Router, extract::State, routing::get};
|
||||
use utoipa::OpenApi;
|
||||
|
||||
use crate::{AppState, health};
|
||||
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(health::live, health::ready),
|
||||
components(schemas(health::Live, health::Ready)),
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user