0040. Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Amends ADR 0027 (its v1 scope and its 422 answer are superseded). Hard cutover: no aliases, no dual routes, no toggles. It must deploy together with the rest of the fleet's REST cutover set.
Context
The fleet REST API guideline (warehouse-docs) removes divergences measured
across the services: three command-URL styles, two spellings of the replay
header, key reuse answered 422, unkeyed writes and unpaginated lists. The
guideline is enforced by .spectral.yaml + .spectral/functions/restGuideline.js
(rules R1-R8) in the api-lint job.
Decision
-
Noun routes. URLs name things; a command is a transition resource.
Old New POST /associates/{id}/start-shiftPOST /associates/{id}/shift-startsPOST /associates/{id}/end-shiftPOST /associates/{id}/shift-endsPOST /associates/{id}/break/startPOST /associates/{id}/break-startsPOST /associates/{id}/break/endPOST /associates/{id}/break-endsPOST /paths/{pathId}/plan/proposePOST /paths/{pathId}/plan-proposalsoperationIds, status codes and bodies are unchanged.TestRetiredRoutesAreGoneasserts the old routes answer 404/405. -
Every POST is idempotent.
RequireIdempotencyKeywraps all eight POST routes (route-scoped). The key is global: the row is found by key alone and compared by fingerprint (method + path + SHA-256 of the body). Same key and fingerprint replays the stored answer withIdempotency-Replayed: true; a different fingerprint is409problemidempotency-key-reused(was 422); a missing key is400 idempotency-key-required; a key that is not 1-128 printable ASCII is400 idempotency-key-invalid.Idempotent-Replayedis retired. The key row, the aggregate change and the outbox rows still commit in one transaction (every use case already runs in theUnitOfWork, which joins the middleware's transaction throughinternal/pgtx); 2xx and 4xx are stored, a 5xx or panic rolls back and is never stored.PUT/DELETEdo not exist on this service, so no keyless-by-method exception applies. -
Keyset pagination.
GET /sites/{siteCode}/shifts/{shiftId}/staffing-gapand the deprecatedGET /buildings/{buildingId}/shifts/{shiftId}/staffing-gaptakelimit(1-500, default 100) andcursorand answer{items,nextCursor}, ordered bypathId(unique within a plan) via the sharedpagehelper (internal/adapters/inbound/http/page). The gaps are computed from the committed plan's lines (a bounded in-memory set, not a SQL query), so the keyset is applied to that sorted slice. Badlimitis400 invalid-limit, bad or repeatedcursor400 invalid-cursor, any other query parameter400 unknown-query-parameter.
Exemptions
None. GET /paths/{pathId}/staffing-gap is a single-path lookup (an item, not a
collection) and /reports/labor belongs to the separate reports API.
Consumers changed
web/ (staffing-gap screen follows nextCursor, fetchAllPages), the BDD
steps and e2e helpers in this repo. Outside this repo: e2e-tests
(cmd/warehouse-day/floor.go, sim.go, e2e_test.go) call the renamed routes.
Consequences
Breaking for every client of the five renamed routes, every POST caller (a key
is now required) and every reader of the staffing-gap lists. The deprecated
/buildings/... staffing-gap alias predates this ADR and is untouched apart
from paging.