Add OpenAPI support and health info endpoint documentation
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
mod api;
|
||||
mod view;
|
||||
|
||||
pub use self::api::ApiDoc;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{Extension, Router};
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
mod health;
|
||||
mod openapi;
|
||||
|
||||
pub use self::openapi::ApiDoc;
|
||||
|
||||
use axum::{Router, response::IntoResponse, routing::any};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
mod info;
|
||||
pub mod info;
|
||||
mod state;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -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>) {
|
||||
|
||||
3
apps/api/src/routes/api/openapi.rs
Normal file
3
apps/api/src/routes/api/openapi.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
#[derive(utoipa::OpenApi)]
|
||||
#[openapi(paths(crate::routes::api::health::info::get_health_info))]
|
||||
pub struct ApiDoc;
|
||||
Reference in New Issue
Block a user