Add OpenAPI support and health info endpoint documentation

This commit is contained in:
GW_MC
2025-12-05 17:01:29 +08:00
parent efdb47a117
commit 34ebfaddbc
7 changed files with 48 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
mod api;
mod view;
pub use self::api::ApiDoc;
use std::sync::Arc;
use axum::{Extension, Router};

View File

@@ -1,4 +1,7 @@
mod health;
mod openapi;
pub use self::openapi::ApiDoc;
use axum::{Router, response::IntoResponse, routing::any};

View File

@@ -1,4 +1,4 @@
mod info;
pub mod info;
mod state;
use std::sync::Arc;

View File

@@ -9,7 +9,7 @@ use crate::routes::api::health::state::HealthState;
const STATUS_HEALTHY: &str = "healthy";
const STATUS_UNHEALTHY: &str = "unhealthy";
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
pub struct HealthInfo {
pub status: String,
pub version: String,
@@ -18,6 +18,17 @@ pub struct HealthInfo {
pub errors: Option<Vec<String>>,
}
#[utoipa::path(
get,
path = "/api/health/info",
responses(
(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"),
)
)]
pub async fn get_health_info(
State(state): State<Arc<HealthState>>,
) -> (StatusCode, Json<HealthInfo>) {

View File

@@ -0,0 +1,3 @@
#[derive(utoipa::OpenApi)]
#[openapi(paths(crate::routes::api::health::info::get_health_info))]
pub struct ApiDoc;