refactor: decompose server module into endpoint-specific files

Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-11 13:01:57 -03:00
parent da0a771683
commit ff588b9db2
6 changed files with 784 additions and 688 deletions

110
src/modes/server/docs.rs Normal file
View File

@@ -0,0 +1,110 @@
use axum::response::{Html, Json};
use serde_json::json;
use super::status::get_status_openapi_spec;
use super::items::get_items_openapi_spec;
use super::content::get_content_openapi_spec;
pub async fn handle_openapi() -> Json<serde_json::Value> {
let mut paths = json!({});
// Merge all endpoint specifications
let status_paths = get_status_openapi_spec();
let items_paths = get_items_openapi_spec();
let content_paths = get_content_openapi_spec();
// Merge the path objects
if let serde_json::Value::Object(ref mut paths_map) = paths {
if let serde_json::Value::Object(status_map) = status_paths {
for (key, value) in status_map {
paths_map.insert(key, value);
}
}
if let serde_json::Value::Object(items_map) = items_paths {
for (key, value) in items_map {
paths_map.insert(key, value);
}
}
if let serde_json::Value::Object(content_map) = content_paths {
for (key, value) in content_map {
paths_map.insert(key, 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": 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)
}