feat: implement OpenAPI documentation with utoipa and Swagger UI integration

Co-authored-by: aider (openai/andrew/openrouter/google/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-13 12:35:11 -03:00
parent c7a843d9ed
commit 8501154084

View File

@@ -1,36 +1,20 @@
use axum::response::Html;
use axum::Router;
use axum::routing::get;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
use crate::modes::server::AppState;
pub async fn handle_swagger_ui() -> Html<&'static str> {
let html = r#"<!DOCTYPE html>
<html>
<head>
<title>Keep API Documentation</title>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3.52.5/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@3.52.5/swagger-ui-bundle.js"></script>
<script>
SwaggerUIBundle({
url: '/api-docs/openapi.json',
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.presets.standalone
]
});
</script>
</body>
</html>"#;
Html(html)
}
#[derive(OpenApi)]
#[openapi(
info(
title = "Keep API",
version = "0.1.0",
description = "Keep and manage temporary files with automatic compression and metadata generation"
)
)]
struct ApiDoc;
pub fn add_routes(router: Router<AppState>) -> Router<AppState> {
router
// Documentation endpoints
.route("/swagger", get(handle_swagger_ui))
.merge(SwaggerUi::new("/swagger").url("/api-docs/openapi.json", ApiDoc::openapi()))
}