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