Skip to main content

API Reference

Three contracts, all living in the repo under apis/ and all linted by Spectral in CI on every push:

ContractFileWhere in these docs
REST (cmd/workforce)apis/openapi.yaml (OpenAPI 3.0.3)REST API — generated from the spec, interactive
Reports REST (read-only, cmd/workforce-reports)apis/openapi-reports.yaml (OpenAPI 3.0.3, ADR 0037)Reports API — generated from the spec
Eventsapis/asyncapi.yaml (AsyncAPI 2.6.0)Events — hand-authored from the spec
Errors—Errors — the RFC 7807 shape and every problem type

The REST pages under API Reference → REST API and API Reference → Reports API are generated by docusaurus-plugin-openapi-docs directly from apis/openapi.yaml and apis/openapi-reports.yaml (npm run clean-api-docs && npm run gen-api-docs in docs/, checked by the docs-api-drift CI job). They are not transcribed by hand, so they cannot drift from the specs.

Reports endpoints (cmd/workforce-reports, default :8092)​

MethodPathOperationSuccessErrors
GET/healthzgetReportsHealthz200 {"status":"ok"}—
GET/reports/laborgetLaborReport200 {"rows":[...]}400 invalid-report-query, 500 report-store-error
GET/reports/labor/freshnessgetLaborReportFreshness200 {"lagSeconds":N}500 report-store-error

TestReportsContract_RoutesMatchSpec and TestReportsContract_ResponsesMatchSpec (internal/adapters/inbound/http/reports_contract_test.go) fail when the reports router and apis/openapi-reports.yaml disagree on a route, a status, a media type, a required property or an undocumented property. See Labor report for the data product itself.

Every endpoint​

12 routes in internal/adapters/inbound/http/router.go; 11 of them are documented in apis/openapi.yaml. The one missing from the spec is the readiness probe GET /readyz (ADR 0022), so the generated REST pages do not show it. Cross-checked route by route:

MethodPathOperationUse caseSuccess
POST/associates/{id}/start-shiftstartAssociateShiftStartAssociateShift201 + Location
POST/associates/{id}/certificationscertifyAssociateCertifyAssociate204
POST/paths/{pathId}/plan/proposeproposePathPlanProposePathPlan200
POST/shift-planscommitShiftPlanCommitShiftPlan201 + Location (requires Idempotency-Key)
POST/associates/{id}/assignmentsassignLaborAssignLabor201 + Location (requires Idempotency-Key)
POST/associates/{id}/break/startstartAssociateBreakStartBreak204
POST/associates/{id}/break/endendAssociateBreakEndBreak204
GET/paths/{pathId}/staffing-gapgetStaffingGapGetStaffingGap.Execute200
GET/sites/{siteCode}/shifts/{shiftId}/staffing-gaplistStaffingGapsForSiteShiftGetStaffingGap.ExecuteAllForSite200 (array) — canonical (ADR 0035)
GET/buildings/{buildingId}/shifts/{shiftId}/staffing-gaplistStaffingGapsForShiftGetStaffingGap.ExecuteAll200 (array) — deprecated, answers Deprecation: true
POST/associates/{id}/end-shiftendAssociateShiftEndAssociateShift204
GET/healthzhealthz—200
GET/readyzreadyz—200 ready / 503 not ready

Grouped by OpenAPI tag: Associates (5), Shift Plans (2), Assignments (1), Staffing (2), System (2).

The two creation POSTs are wrapped in the transactional Idempotency-Key middleware (ADR 0027) whenever the service runs on Postgres (every deployment): a missing key is 400 idempotency-key-required, the same key with a different body is 409 idempotency-key-reused, and a retry with the same key and body replays the stored response. A 5xx answer is never stored: the work and the key roll back, and a retry with the same key runs again.

Conventions​

Resource creation returns 201 with a Location header. Starting a shift, committing a plan and creating an assignment all do this. Commands with no new resource to point at return 204 No Content.

Errors are always RFC 7807. Content type application/problem+json, never a bespoke {"error": ...} shape. See Errors.

Two verbs that look like RPC, and why they stay. POST /associates/{id}/start-shift and .../end-shift are state transitions on a roster entry, not resources. Modelling them as PATCH on an /associates/{id}/shift sub-resource with a status field would be more literally REST-shaped and less legible: "start-shift" is what the domain calls it, and the ubiquitous language wins. They are Level 2 on the Richardson maturity model — correct verbs, correct status codes, resource-scoped URLs — which is where this API deliberately sits.

Identifiers are opaque strings. associateId, pathId, siteCode (the deprecated alias buildingId is the same value) and shiftId are validated as non-empty and otherwise uninterpreted. pathId is a process path name — pack, pick, stow — never a physical location.

DTOs never leak domain types​

Request and response bodies are declared in internal/adapters/inbound/http/dto.go as adapter-local structs. No domain aggregate is ever serialised directly. That is what allows the JSON contract and the domain model to evolve on separate clocks — and it is checked by the arch-go fitness tests, not just by convention.