From 75ff5d4d437485894eadf693613a6dcc186f4716 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:46:16 +0100 Subject: [PATCH] feat(api): the OpenAPI description covers the code graph and chat routes (#1006) The 12 code graph, chat and help chat paths are described from their handlers: the graph, its nodes, summary, communities, a finding's impact, symbol search, file content and rebuild (tag "Code graph"), the code chat and its embeddings (tag "Chat"), and the documentation chat (tag "Help"). The search, file and help chat inputs are schemas; the code chat body stays an object, as it is a core type. undescribed_routes.txt drops to 59 paths. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-agent/src/api/handlers/chat.rs | 37 +++++- compliance-agent/src/api/handlers/graph.rs | 114 ++++++++++++++++-- .../src/api/handlers/help_chat.rs | 23 +++- compliance-agent/src/api/routes.rs | 51 ++------ .../src/api/undescribed_routes.txt | 12 -- 5 files changed, 168 insertions(+), 69 deletions(-) diff --git a/compliance-agent/src/api/handlers/chat.rs b/compliance-agent/src/api/handlers/chat.rs index 73ef8a3..4e48fa5 100644 --- a/compliance-agent/src/api/handlers/chat.rs +++ b/compliance-agent/src/api/handlers/chat.rs @@ -18,7 +18,18 @@ use super::ApiResponse; type AgentExt = Extension>; -/// POST /api/v1/chat/:repo_id — Send a chat message with RAG context +/// Ask about a target's code, answered from its code graph. +#[utoipa::path( + post, + path = "/api/v1/chat/{repo_id}", + tag = "Chat", + params(("repo_id" = String, Path, description = "The target's id")), + request_body(content = Object, description = "`message`, and the earlier `history` as `role` and `content`"), + responses( + (status = 200, description = "The answer with its sources"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn chat( Extension(agent): AgentExt, @@ -133,7 +144,17 @@ pub async fn chat( })) } -/// POST /api/v1/chat/:repo_id/build-embeddings — Trigger embedding build +/// Build the embeddings the chat answers from, in the background. +#[utoipa::path( + post, + path = "/api/v1/chat/{repo_id}/build-embeddings", + tag = "Chat", + params(("repo_id" = String, Path, description = "The target's id")), + responses( + (status = 200, description = "The build was started"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn build_embeddings( Extension(agent): AgentExt, @@ -244,7 +265,17 @@ pub async fn build_embeddings( )) } -/// GET /api/v1/chat/:repo_id/status — Get latest embedding build status +/// The status of a target's latest embedding build. +#[utoipa::path( + get, + path = "/api/v1/chat/{repo_id}/status", + tag = "Chat", + params(("repo_id" = String, Path, description = "The target's id")), + responses( + (status = 200, description = "The build, or null"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn embedding_status( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/handlers/graph.rs b/compliance-agent/src/api/handlers/graph.rs index 2f1899c..84083d3 100644 --- a/compliance-agent/src/api/handlers/graph.rs +++ b/compliance-agent/src/api/handlers/graph.rs @@ -42,14 +42,18 @@ pub struct GraphData { pub total_nodes: u64, } -#[derive(Deserialize)] +/// A symbol search. +#[derive(Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct SearchParams { + /// The search text. pub q: String, /// Clamped to `1..=MAX_PAGE_SIZE` while deserializing, like every list. #[serde( default = "default_search_limit", deserialize_with = "super::dto::de_limit" )] + #[param(minimum = 1, maximum = 200)] pub limit: i64, } @@ -57,7 +61,19 @@ fn default_search_limit() -> i64 { 50 } -/// GET /api/v1/graph/:repo_id — Full graph data +/// A target's code graph: its latest build, nodes and edges. +/// +/// Truncated past a size a browser can lay out, and says so. +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id")), + responses( + (status = 200, description = "The graph"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn get_graph( Extension(agent): AgentExt, @@ -150,7 +166,17 @@ pub async fn get_graph( })) } -/// GET /api/v1/graph/:repo_id/nodes — List nodes (paginated) +/// A target's code graph nodes, a page at a time. +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}/nodes", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id"), PaginationParams), + responses( + (status = 200, description = "A page of nodes"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn get_nodes( Extension(agent): AgentExt, @@ -222,8 +248,19 @@ impl GraphSummary { } } -/// GET /api/v1/graph/:repo_id/summary — The latest build's counts, without -/// loading any node: `data` is `null` when there is none to show. +/// The counts of a target's latest graph build, without loading any node. +/// +/// `data` is `null` when there is none to show. +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}/summary", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id")), + responses( + (status = 200, description = "The counts, or null"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn get_summary( Extension(agent): AgentExt, @@ -244,7 +281,17 @@ pub async fn get_summary( })) } -/// GET /api/v1/graph/:repo_id/communities — List detected communities +/// The communities detected in a target's code graph. +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}/communities", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id")), + responses( + (status = 200, description = "The communities"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn get_communities( Extension(agent): AgentExt, @@ -312,7 +359,17 @@ pub struct CommunityInfo { pub members: Vec, } -/// GET /api/v1/graph/:repo_id/impact/:finding_id — Impact analysis +/// What a finding reaches in a target's code graph. +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}/impact/{finding_id}", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id"), ("finding_id" = String, Path, description = "The finding's id")), + responses( + (status = 200, description = "The impact analysis, or null"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id, finding_id = %finding_id))] pub async fn get_impact( Extension(agent): AgentExt, @@ -336,7 +393,17 @@ pub async fn get_impact( })) } -/// GET /api/v1/graph/:repo_id/search — BM25 symbol search +/// Search a target's code graph for symbols (BM25). +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}/search", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id"), SearchParams), + responses( + (status = 200, description = "The matching nodes"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id, query = %params.q))] pub async fn search_symbols( Extension(agent): AgentExt, @@ -370,7 +437,19 @@ pub async fn search_symbols( })) } -/// GET /api/v1/graph/:repo_id/file-content — Read source file from cloned repo +/// A source file of a target's checkout. +#[utoipa::path( + get, + path = "/api/v1/graph/{repo_id}/file-content", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id"), FileContentParams), + responses( + (status = 200, description = "The file"), + (status = 403, description = "The path leaves the checkout"), + (status = 404, description = "No such target, checkout or file"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn get_file_content( Extension(agent): AgentExt, @@ -431,8 +510,11 @@ pub async fn get_file_content( })) } -#[derive(Deserialize)] +/// The file of [`get_file_content`]. +#[derive(Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct FileContentParams { + /// The file's path in the checkout. pub path: String, } @@ -443,7 +525,17 @@ pub struct FileContent { pub language: String, } -/// POST /api/v1/graph/:repo_id/build — Trigger graph rebuild +/// Rebuild a target's code graph in the background. +#[utoipa::path( + post, + path = "/api/v1/graph/{repo_id}/build", + tag = "Code graph", + params(("repo_id" = String, Path, description = "The target's id")), + responses( + (status = 200, description = "The build was started"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %repo_id))] pub async fn trigger_build( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/handlers/help_chat.rs b/compliance-agent/src/api/handlers/help_chat.rs index 9b219c2..6fee029 100644 --- a/compliance-agent/src/api/handlers/help_chat.rs +++ b/compliance-agent/src/api/handlers/help_chat.rs @@ -11,15 +11,21 @@ use super::dto::{AgentExt, ApiResponse}; // ── DTOs ───────────────────────────────────────────────────────────────────── -#[derive(Debug, Deserialize)] +/// An earlier turn of a help chat. +#[derive(Debug, Deserialize, utoipa::ToSchema)] pub struct HelpChatMessage { + /// `user` or `assistant`. pub role: String, + /// What was said. pub content: String, } -#[derive(Debug, Deserialize)] +/// The body of [`help_chat`]. +#[derive(Debug, Deserialize, utoipa::ToSchema)] pub struct HelpChatRequest { + /// The question. pub message: String, + /// The earlier turns, oldest first. #[serde(default)] pub history: Vec, } @@ -170,8 +176,17 @@ fn doc_context() -> &'static str { // ── Handler ────────────────────────────────────────────────────────────────── -/// POST /api/v1/help/chat — Answer questions about the compliance-scanner -/// using the project documentation as grounding context. +/// Ask about Prüfwerk, answered from its published documentation. +#[utoipa::path( + post, + path = "/api/v1/help/chat", + tag = "Help", + request_body = HelpChatRequest, + responses( + (status = 200, description = "The answer"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn help_chat( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/routes.rs b/compliance-agent/src/api/routes.rs index e5a9c2f..0790bb9 100644 --- a/compliance-agent/src/api/routes.rs +++ b/compliance-agent/src/api/routes.rs @@ -234,35 +234,14 @@ fn described_routes() -> OpenApiRouter { delete(handlers::mcp_tokens::revoke_mcp_token), ) // Graph API endpoints - .route("/api/v1/graph/{repo_id}", get(handlers::graph::get_graph)) - .route( - "/api/v1/graph/{repo_id}/nodes", - get(handlers::graph::get_nodes), - ) - .route( - "/api/v1/graph/{repo_id}/summary", - get(handlers::graph::get_summary), - ) - .route( - "/api/v1/graph/{repo_id}/communities", - get(handlers::graph::get_communities), - ) - .route( - "/api/v1/graph/{repo_id}/impact/{finding_id}", - get(handlers::graph::get_impact), - ) - .route( - "/api/v1/graph/{repo_id}/search", - get(handlers::graph::search_symbols), - ) - .route( - "/api/v1/graph/{repo_id}/file-content", - get(handlers::graph::get_file_content), - ) - .route( - "/api/v1/graph/{repo_id}/build", - post(handlers::graph::trigger_build), - ) + .routes(routes!(handlers::graph::get_graph)) + .routes(routes!(handlers::graph::get_nodes)) + .routes(routes!(handlers::graph::get_summary)) + .routes(routes!(handlers::graph::get_communities)) + .routes(routes!(handlers::graph::get_impact)) + .routes(routes!(handlers::graph::search_symbols)) + .routes(routes!(handlers::graph::get_file_content)) + .routes(routes!(handlers::graph::trigger_build)) // DAST API endpoints .routes(routes!( handlers::dast::list_targets, @@ -273,17 +252,11 @@ fn described_routes() -> OpenApiRouter { .routes(routes!(handlers::dast::list_findings)) .routes(routes!(handlers::dast::get_finding)) // Chat / RAG API endpoints - .route("/api/v1/chat/{repo_id}", post(handlers::chat::chat)) - .route( - "/api/v1/chat/{repo_id}/build-embeddings", - post(handlers::chat::build_embeddings), - ) - .route( - "/api/v1/chat/{repo_id}/status", - get(handlers::chat::embedding_status), - ) + .routes(routes!(handlers::chat::chat)) + .routes(routes!(handlers::chat::build_embeddings)) + .routes(routes!(handlers::chat::embedding_status)) // Help chat (documentation-grounded Q&A) - .route("/api/v1/help/chat", post(handlers::help_chat::help_chat)) + .routes(routes!(handlers::help_chat::help_chat)) // CVE notification endpoints .route( "/api/v1/notifications", diff --git a/compliance-agent/src/api/undescribed_routes.txt b/compliance-agent/src/api/undescribed_routes.txt index 0f7e7b2..999b710 100644 --- a/compliance-agent/src/api/undescribed_routes.txt +++ b/compliance-agent/src/api/undescribed_routes.txt @@ -44,18 +44,6 @@ /api/v1/mcp-servers/{id}/token /api/v1/mcp-tokens /api/v1/mcp-tokens/{id} -/api/v1/graph/{repo_id} -/api/v1/graph/{repo_id}/nodes -/api/v1/graph/{repo_id}/summary -/api/v1/graph/{repo_id}/communities -/api/v1/graph/{repo_id}/impact/{finding_id} -/api/v1/graph/{repo_id}/search -/api/v1/graph/{repo_id}/file-content -/api/v1/graph/{repo_id}/build -/api/v1/chat/{repo_id} -/api/v1/chat/{repo_id}/build-embeddings -/api/v1/chat/{repo_id}/status -/api/v1/help/chat /api/v1/notifications /api/v1/notifications/count /api/v1/notifications/read-all