API overview
| Interface | Source of truth | Notes |
|---|---|---|
| REST | apis/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). |
| Events | apis/asyncapi.yaml | Summarised on the event catalogue; every field on Domain events. |
| MCP | internal/adapters/inbound/mcp | cmd/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
| Tag | Endpoint | Use case | Success |
|---|---|---|---|
| Returns | POST /returns | AuthorizeReturn | 201 + Location; a decided rejection is 409 return-not-authorizable with a rejection code |
| Returns | GET /returns?orderRef= | ListReturnsByOrder | 200 {items}; unknown order answers 200 with [], never 404 |
| Returns | GET /returns/{rmaId} | GetReturn | 200, the RMA |
| Receipts | POST /returns/{rmaId}/receipts | OpenReturnReceipt | 201 + Location |
| Receipts | POST /receipts/{receiptId}/lines/{lineNo}/inspections | InspectReturnLine | 200 with the receipt line and the decided disposition (same transaction) |
| Dispositions | POST /dispositions/{dispositionId}/overrides | OverrideDisposition | 200, the superseding disposition |
| Disposition policies | PUT /disposition-policies/{version} | DeclareDispositionPolicy | 201; append-only |
| Disposition policies | GET /disposition-policies/current | GetDispositionPolicy | 200, the current version |
| Health | GET /healthz | liveness | 200 |
| Health | GET /readyz | drain gate + Postgres ping + Kafka metadata | 200 / 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: falseeverywhere): unknown fields are400 malformed-request-body. A NUL byte in a path is404, in a body400. JSON names are camelCase on REST and snake_case in eventdata. Idempotency-Keyis required on every write — the four POSTs and the policy PUT. A missing key is400 idempotency-key-required(a malformed one400 idempotency-key-invalid); the same key, method, path and body replays the stored answer (4xx included) withIdempotency-Replayed: true; the same key with another method, path or body is409 idempotency-key-reused. A 5xx is never stored.- Pagination.
GET /returnsis keyset-paged:limit(1–500, default 100) and an opaquecursor; the answer is{items, nextCursor}andnextCursoris absent on the last page. A badlimitis400 invalid-limit, an undecodablecursor400 invalid-cursor. - Versions. Aggregate
versionguards every write: a lost update is409 concurrent-modification. The policy is append-only byversionpath segment (a version that exists is409 policy-version-exists); an RMA move and a receipt write bump their aggregates' versions. - Errors are RFC 7807
application/problem+jsonwithtype = 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 (
TestNoAuthMiddlewareReintroducedfails CI if auth middleware returns). No CORS middleware.