Skip to main content

API overview

InterfaceSource of truthNotes
RESTapis/openapi.yaml (OpenAPI 3.0.3, version 1.0.0)The pages under REST are generated from the spec with npm run gen-api-docs; do not edit them by hand. Servers declared in the spec: http://localhost:8080 (local) and http://localhost:8000/api/returns-processing (Kong in the local kind cluster; not wired in warehouse-infra yet).
Eventsapis/asyncapi.yamlSummarised on the event catalogue; every field on Domain events.
MCPinternal/adapters/inbound/mcpcmd/mcp, Streamable HTTP on :8090 at /mcp: read-only tools get_return, list_returns_by_order, get_disposition_policy (MCP tools). Writes stay on REST.

Endpoints​

TagEndpointUse caseSuccess
ReturnsPOST /returnsAuthorizeReturn201 + Location; a decided rejection is 409 return-not-authorizable with a rejection code
ReturnsGET /returns?orderRef=ListReturnsByOrder200 {items}; unknown order answers 200 with [], never 404
ReturnsGET /returns/{rmaId}GetReturn200, the RMA
ReceiptsPOST /returns/{rmaId}/receiptsOpenReturnReceipt201 + Location
ReceiptsPOST /receipts/{receiptId}/lines/{lineNo}/inspectionsInspectReturnLine200 with the receipt line and the decided disposition (same transaction)
DispositionsPOST /dispositions/{dispositionId}/overridesOverrideDisposition200, the superseding disposition
Disposition policiesPUT /disposition-policies/{version}DeclareDispositionPolicy201; append-only
Disposition policiesGET /disposition-policies/currentGetDispositionPolicy200, the current version
HealthGET /healthzliveness200
HealthGET /readyzdrain gate + Postgres ping + Kafka metadata200 / 503 dependency-unavailable

Metrics are pushed over OTLP, not scraped, so the spec declares no /metrics route (see Observability). The four GET /reports/* routes are served by the separate returns-reports binary (:8092) and are bounded by from/to, so they are unpaginated (x-pagination-exempt).

Conventions​

  • Bodies. Strict JSON (additionalProperties: false everywhere): unknown fields are 400 malformed-request-body. A NUL byte in a path is 404, in a body 400. JSON names are camelCase on REST and snake_case in event data.
  • Idempotency-Key is required on every write — the four POSTs and the policy PUT. A missing key is 400 idempotency-key-required (a malformed one 400 idempotency-key-invalid); the same key, method, path and body replays the stored answer (4xx included) with Idempotency-Replayed: true; the same key with another method, path or body is 409 idempotency-key-reused. A 5xx is never stored.
  • Pagination. GET /returns is keyset-paged: limit (1–500, default 100) and an opaque cursor; the answer is {items, nextCursor} and nextCursor is absent on the last page. A bad limit is 400 invalid-limit, an undecodable cursor 400 invalid-cursor.
  • Versions. Aggregate version guards every write: a lost update is 409 concurrent-modification. The policy is append-only by version path segment (a version that exists is 409 policy-version-exists); an RMA move and a receipt write bump their aggregates' versions.
  • Errors are RFC 7807 application/problem+json with type = https://errors.returns-processing.warehouse-systems.dev/<slug>. The slugs: malformed-request-body, invalid-quantity, invalid-line, invalid-grade, invalid-policy, idempotency-key-required, idempotency-key-invalid, idempotency-key-reused, invalid-limit, invalid-cursor, rma-not-found, receipt-not-found, disposition-not-found, policy-not-found, return-not-authorizable, open-rma-exists, rma-not-receivable, line-already-inspected, inspected-exceeds-received, override-reason-required, concurrent-modification, policy-version-exists, dependency-unavailable, internal-error. Causes and fixes are on Troubleshooting.
  • Auth: none (TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns). No CORS middleware.