From 20714bf9236dae82769a859185e73da72027813a Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:26:47 +0100 Subject: [PATCH] feat(api): the OpenAPI description covers health, workspace and support routes (#1006) The 8 paths are described from their handlers: the public health check (tag "Health", no bearer requirement), access, overview stats, projects, metering usage and the git source (tag "Workspace"), and support's tenant list and session (tag "Support"). undescribed_routes.txt drops to 31 paths. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- .../src/api/handlers/git_source.rs | 16 ++++++- compliance-agent/src/api/handlers/health.rs | 45 ++++++++++++++++--- compliance-agent/src/api/handlers/metering.rs | 15 ++++++- compliance-agent/src/api/handlers/projects.rs | 13 +++++- compliance-agent/src/api/handlers/support.rs | 31 +++++++++++-- compliance-agent/src/api/routes.rs | 25 ++++------- .../src/api/undescribed_routes.txt | 8 ---- 7 files changed, 112 insertions(+), 41 deletions(-) diff --git a/compliance-agent/src/api/handlers/git_source.rs b/compliance-agent/src/api/handlers/git_source.rs index 17f598d..f0af6f5 100644 --- a/compliance-agent/src/api/handlers/git_source.rs +++ b/compliance-agent/src/api/handlers/git_source.rs @@ -17,8 +17,20 @@ fn may_view(tenant: &TenantCtx) -> bool { tenant.0.staff.is_some() || tenant.0.is_admin() } -/// The source without secrets, plus the webhook URL; `data: null` when the -/// workspace has none. +/// The workspace's managed git source, without secrets. +/// +/// Plus the webhook URL; `data: null` when the workspace has none. For +/// administrators (IT_ADMIN, OWNER) and support. +#[utoipa::path( + get, + path = "/api/v1/git-source", + tag = "Workspace", + responses( + (status = 200, description = "The source, or null"), + (status = 403, description = "Not an administrator or support"), + (status = 401, description = "No valid bearer token"), + ) +)] pub async fn get_git_source( axum::extract::Extension(agent): AgentExt, tenant: TenantCtx, diff --git a/compliance-agent/src/api/handlers/health.rs b/compliance-agent/src/api/handlers/health.rs index caa8e4f..40862da 100644 --- a/compliance-agent/src/api/handlers/health.rs +++ b/compliance-agent/src/api/handlers/health.rs @@ -5,9 +5,21 @@ use super::dto::*; use compliance_core::models::ScanRun; use compliance_core::tenant_ctx::TenantCtx; -/// `GET /api/v1/access`: reached only when the authentication, entitlement -/// and role layers let the caller through; they answer the refusals (a -/// blocked member gets 403 `MEMBER_BLOCKED`). +/// Whether the caller may use Prüfwerk at all. +/// +/// Reached only when the authentication, entitlement and role layers let the +/// caller through; they answer the refusals (a blocked member gets 403 +/// `MEMBER_BLOCKED`). +#[utoipa::path( + get, + path = "/api/v1/access", + tag = "Workspace", + responses( + (status = 200, description = "The caller may use Prüfwerk"), + (status = 403, description = "Not entitled, or a blocked member"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn access() -> Json { Json(serde_json::json!({ "access": true })) @@ -16,10 +28,21 @@ pub async fn access() -> Json { /// How long the health check waits for MongoDB before it reports it down. const DB_PING_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(2); -/// `GET /api/v1/health`: 200 `{"status":"ok"}` when MongoDB answers a ping, -/// 503 `{"status":"degraded","mongo":"unreachable"}` when it does not, so a -/// load balancer and the container health check stop sending traffic to an +/// Whether the agent can serve: MongoDB answers a ping. +/// +/// 200 `{"status":"ok"}` when MongoDB answers, 503 +/// `{"status":"degraded","mongo":"unreachable"}` when it does not, so a load +/// balancer and the container health check stop sending traffic to an /// instance that cannot serve it (#60). Public, untraced, no tenant. +#[utoipa::path( + get, + path = "/api/v1/health", + tag = "Health", + responses( + (status = 200, description = "MongoDB answers"), + (status = 503, description = "MongoDB is unreachable"), + ) +)] #[tracing::instrument(skip_all)] pub async fn health( axum::extract::Extension(agent): AgentExt, @@ -93,6 +116,16 @@ pub(crate) async fn open_findings_by_severity( .collect() } +/// The counts the overview page shows for the tenant. +#[utoipa::path( + get, + path = "/api/v1/stats/overview", + tag = "Workspace", + responses( + (status = 200, description = "The counts"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn stats_overview( axum::extract::Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/handlers/metering.rs b/compliance-agent/src/api/handlers/metering.rs index ea196a8..2bd77e2 100644 --- a/compliance-agent/src/api/handlers/metering.rs +++ b/compliance-agent/src/api/handlers/metering.rs @@ -27,12 +27,23 @@ struct UsageView { prueftag_cap: Option, } -/// GET /api/v1/metering/usage — the tenant's Prüfungen, Prüftage and extra -/// targets this month (Europe/Berlin), with the plan's limits. +/// The tenant's usage this month, with the plan's limits. +/// +/// Prüfungen, Prüftage and extra targets this month (Europe/Berlin). /// /// # Errors /// /// `500` when the counters cannot be read. +#[utoipa::path( + get, + path = "/api/v1/metering/usage", + tag = "Workspace", + responses( + (status = 200, description = "The usage"), + (status = 500, description = "The counters cannot be read"), + (status = 401, description = "No valid bearer token"), + ) +)] pub async fn get_usage( Extension(agent): AgentExt, tenant: TenantCtx, diff --git a/compliance-agent/src/api/handlers/projects.rs b/compliance-agent/src/api/handlers/projects.rs index e643e67..7a06e66 100644 --- a/compliance-agent/src/api/handlers/projects.rs +++ b/compliance-agent/src/api/handlers/projects.rs @@ -106,8 +106,17 @@ pub fn projects_changed_entry( ) } -/// GET /api/v1/projects — the tenant's projects, for choosing and showing -/// them in the dashboard. +/// The tenant's projects, for choosing and showing them in the dashboard. +#[utoipa::path( + get, + path = "/api/v1/projects", + tag = "Workspace", + responses( + (status = 200, description = "The projects"), + (status = 503, description = "The registry cannot be asked"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn list_projects( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/handlers/support.rs b/compliance-agent/src/api/handlers/support.rs index 5ebb86d..9594472 100644 --- a/compliance-agent/src/api/handlers/support.rs +++ b/compliance-agent/src/api/handlers/support.rs @@ -41,8 +41,20 @@ fn picker_order(mut tenants: Vec) -> Vec { tenants } -/// GET /api/v1/support/tenants — every tenant, for support to choose from. +/// Every tenant, for Breakpilot support to choose from. +/// /// 403 for anyone but support; 503 without a registry. +#[utoipa::path( + get, + path = "/api/v1/support/tenants", + tag = "Support", + responses( + (status = 200, description = "The tenants"), + (status = 403, description = "Not support"), + (status = 503, description = "No registry"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn list_tenants( Extension(agent): AgentExt, @@ -60,9 +72,20 @@ pub async fn list_tenants( Ok(Json(serde_json::json!({ "data": tenants }))) } -/// POST /api/v1/support/session — open the tenant named in the header. The -/// middleware has confirmed it with the registry and records the opening in -/// the audit log; this answers what was opened. 403 for anyone but support. +/// Open the tenant named in the `X-Pruefwerk-Tenant` header for support. +/// +/// The middleware has confirmed it with the registry and records the opening +/// in the audit log; this answers what was opened. 403 for anyone but support. +#[utoipa::path( + post, + path = "/api/v1/support/session", + tag = "Support", + responses( + (status = 200, description = "The opened tenant"), + (status = 403, description = "Not support"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn open_session(tenant: TenantCtx) -> Result, StatusCode> { if tenant.0.staff.is_none() { diff --git a/compliance-agent/src/api/routes.rs b/compliance-agent/src/api/routes.rs index bfd9722..f37e0fb 100644 --- a/compliance-agent/src/api/routes.rs +++ b/compliance-agent/src/api/routes.rs @@ -40,30 +40,21 @@ pub fn build_router() -> Router { fn described_routes() -> OpenApiRouter { OpenApiRouter::with_openapi(openapi::ApiDoc::openapi()) - .route("/api/v1/health", get(handlers::health)) + .routes(routes!(handlers::health)) .routes(routes!(handlers::oscal::assess_target)) - .route("/api/v1/stats/overview", get(handlers::stats_overview)) + .routes(routes!(handlers::stats_overview)) // The tenant's projects (owned by the registry), for assigning targets. - .route("/api/v1/projects", get(handlers::projects::list_projects)) - .route("/api/v1/metering/usage", get(handlers::metering::get_usage)) + .routes(routes!(handlers::projects::list_projects)) + .routes(routes!(handlers::metering::get_usage)) // Whether the caller may use Prüfwerk at all: answered by the // authentication and entitlement layers in front of it (a blocked // member gets 403 MEMBER_BLOCKED), for the dashboard's sign-in check. - .route("/api/v1/access", get(handlers::health::access)) + .routes(routes!(handlers::health::access)) // The managed git source, read-only (IT admin and support). - .route( - "/api/v1/git-source", - get(handlers::git_source::get_git_source), - ) + .routes(routes!(handlers::git_source::get_git_source)) // BreakPilot support access: choose and open a customer's tenant. - .route( - "/api/v1/support/tenants", - get(handlers::support::list_tenants), - ) - .route( - "/api/v1/support/session", - post(handlers::support::open_session), - ) + .routes(routes!(handlers::support::list_tenants)) + .routes(routes!(handlers::support::open_session)) // Unified onboarding targets (#131). .routes(routes!( handlers::onboarding::list_targets, diff --git a/compliance-agent/src/api/undescribed_routes.txt b/compliance-agent/src/api/undescribed_routes.txt index 4d89590..b1172b2 100644 --- a/compliance-agent/src/api/undescribed_routes.txt +++ b/compliance-agent/src/api/undescribed_routes.txt @@ -3,14 +3,6 @@ # `.route("...")` in routes.rs is missing here, or when a line here names no # such route, so the list only ever shrinks. Describe a route with # `#[utoipa::path]` and `.routes(routes!(...))`, then delete its line. -/api/v1/health -/api/v1/stats/overview -/api/v1/projects -/api/v1/metering/usage -/api/v1/access -/api/v1/git-source -/api/v1/support/tenants -/api/v1/support/session /api/v1/inbox /api/v1/inbox/decide /api/v1/inbox/undo -- 2.54.1