From 8caf01ca073f8a62086cbdd38b62536fd78479b8 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 16 Nov 2026 22:09:32 +0100 Subject: [PATCH] feat(api): the OpenAPI description covers the inbox routes (#1006) The 5 inbox paths are described from their handlers (tag "Inbox"): the buckets and cards, deciding on a card, undoing a decision, putting a card off and taking that back. InboxQuery is a schema; the bodies are core types and stay objects with a description. undescribed_routes.txt drops to 26 paths, the CVE/VEX and pentest routes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-agent/src/api/handlers/inbox.rs | 115 ++++++++++++++---- compliance-agent/src/api/routes.rs | 15 +-- .../src/api/undescribed_routes.txt | 5 - 3 files changed, 98 insertions(+), 37 deletions(-) diff --git a/compliance-agent/src/api/handlers/inbox.rs b/compliance-agent/src/api/handlers/inbox.rs index b0d5850..b4a1f81 100644 --- a/compliance-agent/src/api/handlers/inbox.rs +++ b/compliance-agent/src/api/handlers/inbox.rs @@ -55,16 +55,20 @@ fn store_error(e: mongodb::error::Error) -> Refusal { } /// The query of [`get_inbox`]. -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct InboxQuery { /// Only this target's cards, counts and Erstbewertung. #[serde(default)] pub target: Option, - /// The bucket whose cards to list (default `today`). + /// The bucket whose cards to list: `today` (default), `this_week`, + /// `later` or `likely_false_positive`. #[serde(default)] + #[param(value_type = Option, example = "this_week")] pub bucket: Option, /// The most cards to list (default 100, at most 500). #[serde(default)] + #[param(minimum = 1, maximum = 500)] pub limit: Option, } @@ -174,13 +178,24 @@ async fn progress( }) } -/// GET /api/v1/inbox[?target=&bucket=&limit=] — the bucket -/// counts, the Erstbewertung, the targets with cards, and the cards of one -/// bucket (default `today`), most urgent first. +/// The open decisions in urgency buckets, most urgent first. +/// +/// The bucket counts, the Erstbewertung, the targets with cards, and the +/// cards of one bucket (default `today`). /// /// Cards: one per finding, one per target, package and version for CVE /// alerts. Cards put off until a date are left out until then and come back /// under `later`. +#[utoipa::path( + get, + path = "/api/v1/inbox", + tag = "Inbox", + params(InboxQuery), + responses( + (status = 200, description = "The buckets and cards"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(target = ?query.target, bucket = ?query.bucket))] pub async fn get_inbox( Extension(agent): AgentExt, @@ -324,13 +339,27 @@ async fn set_vex( Ok(()) } -/// POST /api/v1/inbox/decide `{key, action, reason?, justification?, -/// statement?}` — apply `action` to every item of card `key`, through the -/// findings' and the VEX endpoints' code, and answer what each item was -/// before (for `POST /api/v1/inbox/undo`). The card's resubmission, if any, -/// is dropped. 409 when nothing on the card waits any more, 422 for an action -/// the card does not offer or without the reason, justification or statement -/// it needs. +/// Decide on every item of a card. +/// +/// `{key, action, reason?, justification?, statement?}`: apply `action` +/// through the findings' and the VEX endpoints' code, and answer what each +/// item was before (for `POST /api/v1/inbox/undo`). The card's resubmission, +/// if any, is dropped. 409 when nothing on the card waits any more, 422 for an +/// action the card does not offer or without the reason, justification or +/// statement it needs. +#[utoipa::path( + post, + path = "/api/v1/inbox/decide", + tag = "Inbox", + request_body(content = Object, description = "`key`, `action`, and the `reason`, `justification` or `statement` the action needs"), + responses( + (status = 200, description = "Decided, with what each item was before"), + (status = 400, description = "A malformed key"), + (status = 409, description = "Nothing on the card waits for a decision"), + (status = 422, description = "An action the card does not offer, or what it needs is missing"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(key = %req.key, action = ?req.action))] pub async fn decide( agent: AgentExt, @@ -431,12 +460,26 @@ async fn belongs_to(db: &Database, key: &str, previous: &[PreviousState]) -> Res } } -/// POST /api/v1/inbox/undo `{key, previous}` — put the items of a decision -/// on card `key` back, through the same code the decision went through: a -/// finding gets its previous status (a new entry in its history, which keeps -/// the decision on record), an alert `under_investigation` (also when it had -/// no statement before; both leave it open). 422 when an item does not -/// belong to the card or its previous state was not an open one. +/// Undo a decision on a card. +/// +/// `{key, previous}`: put the items back through the same code the decision +/// went through. A finding gets its previous status (a new entry in its +/// history, which keeps the decision on record), an alert +/// `under_investigation` (also when it had no statement before; both leave +/// it open). 422 when an item does not belong to the card or its previous +/// state was not an open one. +#[utoipa::path( + post, + path = "/api/v1/inbox/undo", + tag = "Inbox", + request_body(content = Object, description = "`key`, and `previous` as the decision answered it"), + responses( + (status = 200, description = "Put back"), + (status = 400, description = "A malformed key or id"), + (status = 422, description = "An item not of the card, or not open before"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(key = %req.key))] pub async fn undo( agent: AgentExt, @@ -486,13 +529,27 @@ pub async fn undo( Ok(Json(serde_json::json!({ "status": "restored" }))) } -/// POST /api/v1/inbox/snooze `{key, for}` — put card `key` off: one week, one -/// month, or until a date (`{"kind": "date", "date": "2026-12-01"}`). It is -/// hidden until then and comes back in its own bucket, or earlier when a new +/// Put a card off: one week, one month, or until a date. +/// +/// `{key, for}`, `for` as `{"kind": "week"}`, `{"kind": "month"}` or +/// `{"kind": "date", "date": "2026-12-01"}`. It is hidden until then and comes back in its own bucket, or earlier when a new /// CVE or a KEV entry joins it: the snooze records the card's items and /// whether it was KEV. A second snooze replaces the first. 400 for a /// malformed key, 409 when nothing on the card waits for a decision, 422 for /// a date that is not in the future. +#[utoipa::path( + post, + path = "/api/v1/inbox/snooze", + tag = "Inbox", + request_body(content = Object, description = "`key`, and `for`: a week, a month or a date"), + responses( + (status = 200, description = "When the card comes back"), + (status = 400, description = "A malformed key"), + (status = 409, description = "Nothing on the card waits for a decision"), + (status = 422, description = "A date that is not in the future"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(key = %req.key))] pub async fn snooze( Extension(agent): AgentExt, @@ -532,8 +589,20 @@ pub async fn snooze( })) } -/// DELETE /api/v1/inbox/snooze/{key} — take card `key`'s resubmission back -/// (the undo of a snooze); nothing to take back is no error. +/// Take a card's resubmission back (the undo of a snooze). +/// +/// Nothing to take back is no error. +#[utoipa::path( + delete, + path = "/api/v1/inbox/snooze/{key}", + tag = "Inbox", + params(("key" = String, Path, description = "The card's key")), + responses( + (status = 200, description = "The resubmission is gone"), + (status = 400, description = "A malformed key"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(key = %key))] pub async fn unsnooze( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/routes.rs b/compliance-agent/src/api/routes.rs index f37e0fb..aff4ade 100644 --- a/compliance-agent/src/api/routes.rs +++ b/compliance-agent/src/api/routes.rs @@ -1,6 +1,6 @@ use axum::extract::DefaultBodyLimit; use axum::http::header::CONTENT_TYPE; -use axum::routing::{delete, get, patch, post}; +use axum::routing::{get, patch, post}; use axum::Router; use utoipa::OpenApi; use utoipa_axum::router::{OpenApiRouter, UtoipaMethodRouterExt}; @@ -95,14 +95,11 @@ fn described_routes() -> OpenApiRouter { .routes(routes!(handlers::finding_groups::list_finding_groups)) .routes(routes!(handlers::finding_groups::decide_finding_group)) // The "Heute" inbox (#950): open decisions in urgency buckets. - .route("/api/v1/inbox", get(handlers::inbox::get_inbox)) - .route("/api/v1/inbox/decide", post(handlers::inbox::decide)) - .route("/api/v1/inbox/undo", post(handlers::inbox::undo)) - .route("/api/v1/inbox/snooze", post(handlers::inbox::snooze)) - .route( - "/api/v1/inbox/snooze/{key}", - delete(handlers::inbox::unsnooze), - ) + .routes(routes!(handlers::inbox::get_inbox)) + .routes(routes!(handlers::inbox::decide)) + .routes(routes!(handlers::inbox::undo)) + .routes(routes!(handlers::inbox::snooze)) + .routes(routes!(handlers::inbox::unsnooze)) // VEX on a target's CVE alerts (#498). .route( "/api/v1/targets/{id}/cves", diff --git a/compliance-agent/src/api/undescribed_routes.txt b/compliance-agent/src/api/undescribed_routes.txt index b1172b2..a28a316 100644 --- a/compliance-agent/src/api/undescribed_routes.txt +++ b/compliance-agent/src/api/undescribed_routes.txt @@ -3,11 +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/inbox -/api/v1/inbox/decide -/api/v1/inbox/undo -/api/v1/inbox/snooze -/api/v1/inbox/snooze/{key} /api/v1/targets/{id}/cves /api/v1/targets/{id}/cve-matrix /api/v1/cve-history