Files
keep/src/modes/server/api/mod.rs
Andrew Phillips 90d4f3f10b fix: add OpenAPI documentation to API endpoints and integrate Swagger UI
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
2025-08-12 16:47:16 -03:00

64 lines
2.3 KiB
Rust

pub mod item;
pub mod status;
use axum::{
routing::{get, post, delete},
Router,
};
use crate::modes::server::common::AppState;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
#[derive(OpenApi)]
#[openapi(
paths(
status::handle_status,
item::handle_list_items,
item::handle_post_item,
item::handle_delete_item,
item::handle_get_item_latest,
item::handle_get_item_latest_meta,
item::handle_get_item_latest_content,
item::handle_get_item,
item::handle_get_item_meta,
item::handle_get_item_content,
),
components(
schemas(
crate::modes::server::common::ApiResponse<crate::modes::server::api::status::StatusInfo>,
crate::modes::server::common::ApiResponse<Vec<crate::modes::server::api::item::ItemInfo>>,
crate::modes::server::common::ApiResponse<crate::modes::server::api::item::ItemInfo>,
crate::modes::server::common::ApiResponse<HashMap<String, String>>,
crate::modes::server::common::ApiResponse<()>,
crate::modes::server::api::status::StatusInfo,
crate::modes::server::api::item::ItemInfo,
)
),
tags(
(name = "status", description = "Status API endpoints"),
(name = "items", description = "Item management API endpoints")
)
)]
struct ApiDoc;
pub fn add_routes(router: Router<AppState>) -> Router<AppState> {
router
// Status endpoints
.route("/api/status", get(status::handle_status))
// Item endpoints
.route("/api/item/", get(item::handle_list_items).post(item::handle_post_item))
.route("/api/item/latest", get(item::handle_get_item_latest))
.route("/api/item/latest/meta", get(item::handle_get_item_latest_meta))
.route("/api/item/latest/content", get(item::handle_get_item_latest_content))
.route("/api/item/:id", get(item::handle_get_item).delete(item::handle_delete_item))
.route("/api/item/:id/meta", get(item::handle_get_item_meta))
.route("/api/item/:id/content", get(item::handle_get_item_content))
}
pub fn add_docs_routes(router: Router<AppState>) -> Router<AppState> {
router
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
}