Refactor health check API to include OpenAPI tagging and enhance HealthInfo schema documentation
This commit is contained in:
@@ -4,20 +4,27 @@ use axum::{Json, extract::State, http::StatusCode};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::routes::api::health::state::HealthState;
|
||||
use crate::routes::api::{health::state::HealthState, openapi::tag::HEALTH_TAG};
|
||||
|
||||
const STATUS_HEALTHY: &str = "healthy";
|
||||
const STATUS_UNHEALTHY: &str = "unhealthy";
|
||||
|
||||
/// System health information
|
||||
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
||||
pub struct HealthInfo {
|
||||
/// Health status: "healthy" or "unhealthy"
|
||||
pub status: String,
|
||||
/// Application version
|
||||
pub version: String,
|
||||
// RFC 3339 formatted timestamp
|
||||
/// RFC 3339 formatted timestamp
|
||||
pub up_since: DateTime<Utc>,
|
||||
/// List of error messages if unhealthy
|
||||
pub errors: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
/// Health check endpoint
|
||||
///
|
||||
/// Returns the health status, version, uptime, and any errors if unhealthy.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/health/info",
|
||||
@@ -25,9 +32,7 @@ pub struct HealthInfo {
|
||||
(status = 200, description = "Health information retrieved successfully", body = HealthInfo),
|
||||
(status = NOT_FOUND, description = "Health information not found")
|
||||
),
|
||||
params(
|
||||
("id" = u64, Path, description = "Pet database id to get Pet for"),
|
||||
)
|
||||
tag = HEALTH_TAG,
|
||||
)]
|
||||
pub async fn get_health_info(
|
||||
State(state): State<Arc<HealthState>>,
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
pub mod tag {
|
||||
/// Health tag constant
|
||||
pub const HEALTH_TAG: &str = "Health";
|
||||
}
|
||||
|
||||
#[derive(utoipa::OpenApi)]
|
||||
#[openapi(paths(crate::routes::api::health::info::get_health_info))]
|
||||
#[openapi(
|
||||
paths(
|
||||
crate::routes::api::health::info::get_health_info
|
||||
),
|
||||
components(
|
||||
schemas(crate::routes::api::health::info::HealthInfo) // Register any schemas used in your paths
|
||||
),
|
||||
tags(
|
||||
(name = tag::HEALTH_TAG, description = "Health information API")
|
||||
)
|
||||
)]
|
||||
pub struct ApiDoc;
|
||||
|
||||
Reference in New Issue
Block a user