hive-c0re: wire up openapi spec + swagger ui (#2872)

This commit is contained in:
damocles 2026-07-31 21:39:46 +02:00 committed by mara
commit 44651544a8
7 changed files with 256 additions and 8 deletions

View file

@ -24,10 +24,17 @@ use axum::{
response::{IntoResponse, Response},
};
use serde::Serialize;
use utoipa::ToSchema;
use crate::host_stats::ServerWarning;
/// `GET /health/live` — liveness. Always `200`; no further checks.
#[utoipa::path(
get,
path = "/health/live",
responses((status = 200, description = "process is up", body = serde_json::Value)),
tag = "health"
)]
pub(super) async fn get_health_live() -> Response {
(
StatusCode::OK,
@ -36,7 +43,7 @@ pub(super) async fn get_health_live() -> Response {
.into_response()
}
#[derive(Serialize)]
#[derive(Serialize, ToSchema)]
struct ReadyBody {
status: &'static str,
warnings: Vec<ServerWarning>,
@ -48,6 +55,15 @@ struct ReadyBody {
/// `{"status":"degraded", ...}`. `warnings` always carries the full
/// current list (including `warn`-level entries not affecting the
/// status) so a poller gets detail either way.
#[utoipa::path(
get,
path = "/health/ready",
responses(
(status = 200, description = "no crit-level warning set", body = ReadyBody),
(status = 503, description = "at least one crit-level warning set", body = ReadyBody),
),
tag = "health"
)]
pub(super) async fn get_health_ready() -> Response {
let warnings = crate::warnings::snapshot();
let degraded = warnings.iter().any(|w| w.level == "crit");