91 lines
2.9 KiB
Rust
91 lines
2.9 KiB
Rust
use axum::response::{Html, Json};
|
|
use serde_json::json;
|
|
|
|
// Remove the invalid imports - we'll access the OpenAPI specs differently
|
|
// For now, we'll create a simplified version that doesn't depend on those functions
|
|
|
|
pub async fn handle_openapi() -> Json<serde_json::Value> {
|
|
let openapi_spec = json!({
|
|
"openapi": "3.0.0",
|
|
"info": {
|
|
"title": "Keep API",
|
|
"version": "1.0.0",
|
|
"description": "REST API for the Keep data storage system"
|
|
},
|
|
"servers": [
|
|
{
|
|
"url": "/",
|
|
"description": "Local server"
|
|
}
|
|
],
|
|
"components": {
|
|
"securitySchemes": {
|
|
"bearerAuth": {
|
|
"type": "http",
|
|
"scheme": "bearer"
|
|
}
|
|
},
|
|
"schemas": {
|
|
"ItemInfo": {
|
|
"type": "object",
|
|
"properties": {
|
|
"id": {"type": "integer"},
|
|
"ts": {"type": "string", "format": "date-time"},
|
|
"size": {"type": "integer", "nullable": true},
|
|
"compression": {"type": "string"},
|
|
"tags": {"type": "array", "items": {"type": "string"}},
|
|
"metadata": {"type": "object"}
|
|
}
|
|
},
|
|
"StatusInfo": {
|
|
"type": "object",
|
|
"properties": {
|
|
"version": {"type": "string"},
|
|
"database_path": {"type": "string"},
|
|
"data_directory": {"type": "string"},
|
|
"compression_engines": {"type": "array", "items": {"type": "string"}},
|
|
"meta_plugins": {"type": "array", "items": {"type": "string"}}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"security": [{"bearerAuth": []}],
|
|
"paths": {}
|
|
});
|
|
|
|
Json(openapi_spec)
|
|
}
|
|
|
|
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: '/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> {
|
|
router
|
|
// Documentation endpoints
|
|
.route("/openapi.json", get(docs::handle_openapi))
|
|
.route("/swagger/", get(docs::handle_swagger_ui))
|
|
}
|