diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 0e712bf..9b81a8e 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -226,7 +226,7 @@ func main() { graphView := graphGroup.Group("") graphView.Use(handlers.RequireView()) { - graphView.GET("", graphHandlers.GetYAML) + graphView.GET("", graphHandlers.GetGraph) graphView.GET("/order", graphHandlers.StartupOrder) graphView.GET("/cycle", graphHandlers.CycleCheck) graphView.GET("/failure", graphHandlers.GetFailureRootCause) diff --git a/backend/docs/docs.go b/backend/docs/docs.go index c1fac0e..7e55485 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -1001,19 +1001,20 @@ const docTemplate = `{ "Bearer": [] } ], - "description": "Returns the service dependency graph as raw YAML text", + "description": "Returns the service dependency graph as JSON", "produces": [ - "text/plain" + "application/json" ], "tags": [ "graph" ], - "summary": "Get dependency graph YAML", + "summary": "Get dependency graph", "responses": { "200": { - "description": "YAML content", + "description": "Dependency graph", "schema": { - "type": "string" + "type": "object", + "additionalProperties": true } } } diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index ac2ee40..4382d0b 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -990,19 +990,20 @@ "Bearer": [] } ], - "description": "Returns the service dependency graph as raw YAML text", + "description": "Returns the service dependency graph as JSON", "produces": [ - "text/plain" + "application/json" ], "tags": [ "graph" ], - "summary": "Get dependency graph YAML", + "summary": "Get dependency graph", "responses": { "200": { - "description": "YAML content", + "description": "Dependency graph", "schema": { - "type": "string" + "type": "object", + "additionalProperties": true } } } diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index ce58038..8b3e4dd 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -1181,17 +1181,18 @@ paths: - auth /graph: get: - description: Returns the service dependency graph as raw YAML text + description: Returns the service dependency graph as JSON produces: - - text/plain + - application/json responses: "200": - description: YAML content + description: Dependency graph schema: - type: string + additionalProperties: true + type: object security: - Bearer: [] - summary: Get dependency graph YAML + summary: Get dependency graph tags: - graph put: diff --git a/backend/internal/handlers/graph.go b/backend/internal/handlers/graph.go index 7b1273e..8f30d1f 100644 --- a/backend/internal/handlers/graph.go +++ b/backend/internal/handlers/graph.go @@ -53,25 +53,52 @@ func (h *GraphHandlers) reload() error { return nil } -// GetGraph returns the current parsed graph. -func (h *GraphHandlers) GetGraph() *graph.Graph { +// LoadedGraph returns the current parsed graph. +func (h *GraphHandlers) LoadedGraph() *graph.Graph { h.mu.RLock() defer h.mu.RUnlock() return h.loaded } -// GetYAML returns the raw YAML content. -// @Summary Get dependency graph YAML -// @Description Returns the service dependency graph as raw YAML text +// GetGraph returns the current dependency graph as JSON. +// @Summary Get dependency graph +// @Description Returns the service dependency graph as JSON // @Tags graph -// @Produce plain -// @Success 200 {string} string "YAML content" +// @Produce json +// @Success 200 {object} map[string]interface{} "Dependency graph" // @Security Bearer // @Router /graph [get] -func (h *GraphHandlers) GetYAML(c *gin.Context) { +func (h *GraphHandlers) GetGraph(c *gin.Context) { h.mu.RLock() defer h.mu.RUnlock() - c.Data(http.StatusOK, "text/yaml", h.yamlData) + + g := h.loaded + if g == nil { + c.JSON(http.StatusOK, gin.H{"nodes": map[string]interface{}{}}) + return + } + + nodes := make(map[string]interface{}) + for _, node := range g.Nodes() { + services := make(map[string]interface{}) + for _, svc := range node.Services { + deps := make([]map[string]interface{}, 0) + for _, dep := range svc.Dependencies { + deps = append(deps, map[string]interface{}{ + "target": dep.Target, + "condition": dep.Condition, + }) + } + services[svc.Name] = map[string]interface{}{ + "dependencies": deps, + } + } + nodes[node.ID] = map[string]interface{}{ + "services": services, + } + } + + c.JSON(http.StatusOK, gin.H{"nodes": nodes}) } // UpdateYAML updates the graph from new YAML text.