feature/openapi #7

Merged
GW_MC merged 10 commits from feature/openapi into master 2025-12-05 20:50:37 +08:00
7 changed files with 48 additions and 2 deletions
Showing only changes of commit 34ebfaddbc - Show all commits

26
Cargo.lock generated
View File

@@ -3820,6 +3820,31 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "utoipa"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fcc29c80c21c31608227e0912b2d7fddba57ad76b606890627ba8ee7964e993"
dependencies = [
"indexmap 2.12.0",
"serde",
"serde_json",
"utoipa-gen",
]
[[package]]
name = "utoipa-gen"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d79d08d92ab8af4c5e8a6da20c47ae3f61a0f1dabc1997cdf2d082b757ca08b"
dependencies = [
"proc-macro2",
"quote",
"regex",
"syn 2.0.110",
"uuid",
]
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.18.1" version = "1.18.1"
@@ -4340,6 +4365,7 @@ dependencies = [
"tower", "tower",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"utoipa",
] ]
[[package]] [[package]]

View File

@@ -20,3 +20,4 @@ serde = { version = "1.0.228", features = ["std", "derive"] }
sea-orm = { workspace = true } sea-orm = { workspace = true }
include_dir = { version = "0.7.4" } include_dir = { version = "0.7.4" }
mime_guess = { version = "2.0.5" } mime_guess = { version = "2.0.5" }
utoipa = { version = "5.4.0", features = ["macros", "axum_extras", "chrono", "decimal", "uuid", "time", "openapi_extensions"] }

View File

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

View File

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

View File

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

View File

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