API Reference
This service exposes two contracts, both kept as source-of-truth artefacts in the repository and both linted by Spectral in CI:
| Contract | File | Rendered here |
|---|---|---|
| REST (synchronous) | apis/openapi.yaml — OpenAPI 3.0.3 | REST API — generated directly from the spec |
| Events (asynchronous) | apis/asyncapi.yaml — AsyncAPI 2.6.0 | Events |
The REST pages under REST API are generated from apis/openapi.yaml by
docusaurus-plugin-openapi-docs at build time. They are not hand-transcribed,
so they cannot drift from the spec the service ships.
Endpoint matrix
All 14 routes registered in internal/adapters/inbound/http/server.go's
NewRouter (including the /readyz readiness probe, ADR 0020) and the two
routes of NewReportsRouter (/reports/*, served by the separate
cmd/inventory-reports binary — see
Inventory Flow & Accuracy Report)
are documented in apis/openapi.yaml. The Reports tag is excluded from the
Schemathesis contract run, which boots only the OLTP binary.
| Method | Path | Operation | Tag | Success | Errors |
|---|---|---|---|---|---|
GET | /healthz | getHealthz | Health | 200 | — |
GET | /readyz | getReadyz | Health | 200 | 503 |
POST | /stock-receipts | receiveStock | Stock | 202 | 400 409 422 500 |
POST | /stowages | stowStock | Stock | 201 | 400 404 409 422 500 |
POST | /reservations | reserveStock | Reservations | 201 | 400 409 422 500 |
GET | /reservations?demandRef= | getReservationsByDemandRef | Reservations | 200 ({items,nextCursor}) | 400 500 |
DELETE | /reservations/{id} | revokeReservation | Reservations | 204 | 404 409 500 |
POST | /reservations/{id}/pick-confirmations | confirmPick | Reservations | 204 | 400 404 409 500 |
GET | /inventory/{sku}/usable | getUsableInventory | Inventory | 200 | 400 500 |
PUT | /bins/{binId} | registerBin | Bins | 200 / 201 | 400 409 422 500 |
GET | /bins/{binId} | getBin | Bins | 200 | 404 500 |
POST | /bins/{binId}/cycle-counts | runCycleCount | Bins | 200 | 400 404 409 422 500 |
PUT | /products/{sku}/classification | classifyProduct (retired, ADR 0034) | Products | — | 410 500 |
GET | /products/{sku}/classification | getProductClassification (deprecated, local copy) | Products | 200 | 404 500 |
GET | /reports/flow-accuracy | getFlowAccuracyReport | Reports | 200 | 400 500 |
GET | /reports/flow-accuracy/freshness | getFlowAccuracyFreshness | Reports | 200 | 500 |
Every POST also takes the Idempotency-Key header
(ADR 0018,
ADR 0049): absent →
400 idempotency-key-required; same key with a different method, path or body
→ 409 idempotency-key-reused; a replay of the same request answers the stored
response with Idempotency-Replayed: true. Every collection GET
(/reservations, /bins/{binId}/containers) is keyset-paged: limit (1-500,
default 100) and cursor in, {items, nextCursor} out (400 invalid-limit /
invalid-cursor on bad input).
Status-code conventions
The status codes are deliberate, not defaults. The reasoning was recorded during the REST hardening pass:
| Code | Used for | Example |
|---|---|---|
200 OK | A read, or a command whose result is the response body | GET /inventory/{sku}/usable; POST /bins/{binId}/cycle-counts returns the reconciliation result |
201 Created | A new addressable resource, with a Location header | POST /stowages → Location: /stock/{id}; POST /reservations → Location: /reservations/{id} |
202 Accepted | Accepted, but no addressable resource exists yet | POST /stock-receipts — a staged receipt has no id and no GET route; the StockUnit is created later, at stow |
204 No Content | A state transition with nothing useful to return | revoke, confirm-pick |
400 Bad Request | Malformed or missing input | empty SKU, empty bin id, unparseable JSON |
404 Not Found | The addressed resource does not exist | unknown reservation, unknown bin |
409 Conflict | Well-formed and addressable, but conflicts with current state | bin full, reservation exceeds usable, reservation already resolved, reservation expired |
422 Unprocessable Entity | Well-formed but semantically invalid values | quantity ≤ 0 (zero-quantity), negative bin capacity or counted quantity (negative-quantity), zero bin capacity |
The 400 / 422 split is the one worth internalising: 400 means "I could
not understand the request," 422 means "I understood it perfectly and it is
not a legal thing to ask for."
Errors: RFC 7807 Problem Details
Every error response uses application/problem+json:
{
"type": "https://errors.inventory-storage.warehouse-systems.dev/insufficient-usable",
"title": "Requested quantity exceeds usable inventory",
"status": 409,
"detail": "requested quantity exceeds usable inventory",
"instance": "/reservations"
}
typeis a stable, unique URI per error category. It is an identifier — it does not have to resolve to a page.titleis a fixed human string for the category; safe to switch on for display, thoughtypeis the machine-readable key.detailis the dynamic message from the underlying typed error.instanceis the request path.
Problem-type catalog
Mapping is one-for-one with the typed domain and application errors, in
internal/adapters/inbound/http/errors.go.
type slug | Status | Raised by |
|---|---|---|
stock-unit-not-found | 404 | usecases.ErrStockUnitNotFound |
bin-not-found | 404 | usecases.ErrBinNotFound |
reservation-not-found | 404 | usecases.ErrReservationNotFound |
product-classification-not-found | 404 | usecases.ErrProductClassificationNotFound |
empty-sku | 400 | shared.ErrEmptySKU |
empty-bin-id | 400 | shared.ErrEmptyBinID |
stow-requires-item-and-location | 400 | stock.ErrStowRequiresItemAndLocation — mapped, but not reachable over REST: the stow handler builds the SKU and BinId value objects first, so a missing scan answers empty-sku / empty-bin-id |
unknown-handling-tag | 400 | product.ErrUnknownHandlingTag |
unknown-temperature-class | 400 | product.ErrUnknownTemperatureClass |
no-handling-tags | 400 | product.ErrNoHandlingTags |
temperature-class-required | 400 | product.ErrTemperatureClassRequired |
temperature-class-not-applicable | 400 | product.ErrTemperatureClassNotApplicable |
duplicate-handling-tag | 400 | product.ErrDuplicateHandlingTag |
invalid-dot-hazard-class | 400 | product.ErrInvalidDOTHazardClass |
dot-hazard-class-not-applicable | 400 | product.ErrDOTHazardClassNotApplicable |
negative-quantity | 422 | shared.ErrNegativeQuantity — only for a negative bin capacity (PUT /bins/{binId}) or countedQuantity (cycle count); a negative quantity on receive, stow, reserve or relocate answers zero-quantity |
zero-quantity | 422 | shared.ErrZeroQuantity — a quantity ≤ 0 on receive, stow, reserve and relocate (NewPositiveQuantity) |
invalid-bin-capacity | 422 | location.ErrInvalidCapacity |
bin-full | 409 | location.ErrBinFull |
capacity-below-occupancy | 409 | location.ErrCapacityBelowOccupancy (PUT /bins/{binId}, ADR 0025) |
release-exceeds-occupancy | 409 | location.ErrReleaseExceedsOccupancy |
insufficient-usable | 409 | usecases.ErrInsufficientUsable, stock.ErrInsufficientUsable |
insufficient-reserved | 409 | stock.ErrInsufficientReserved |
unit-unlocated | 409 | stock.ErrUnitUnlocated |
reservation-already-resolved | 409 | reservation.ErrAlreadyResolved |
reservation-expired | 409 | reservation.ErrExpired |
reservation-no-allocations | 409 | reservation.ErrNoAllocations |
hazmat-zone-required | 409 | usecases.ErrHazmatZoneRequired |
temperature-class-mismatch | 409 | usecases.ErrTemperatureClassMismatch |
location-classification-unavailable | 409 | usecases.ErrLocationClassificationUnavailable |
hazmat-class-incompatible | 409 | usecases.ErrHazmatClassIncompatible |
concurrent-modification | 409 | usecases.ErrConcurrentModification — a version-guarded Save lost an optimistic-concurrency race (ADR 0019); re-fetch and retry |
counted-quantity-required | 400 | written directly by the POST /bins/{binId}/cycle-counts handler when countedQuantity is omitted |
idempotency-key-required | 400 | written by the RequireIdempotencyKey middleware (ADR 0018) |
idempotency-key-invalid | 400 | written by the RequireIdempotencyKey middleware: not 1-128 printable ASCII characters (ADR 0049) |
idempotency-key-reused | 409 | written by the RequireIdempotencyKey middleware (ADR 0018, ADR 0049; was 422) |
invalid-limit | 400 | written by the paginated collection handlers: limit is not an integer in 1..500 (ADR 0049) |
invalid-cursor | 400 | written by the paginated collection handlers: cursor does not decode (ADR 0049) |
invalid-report-query | 400 | written by the reports handlers (GET /reports/flow-accuracy) |
report-store-error | 500 | written by the reports handlers when the read model fails |
missing-demand-ref | 400 | written directly by the GET /reservations and POST /reservations handlers (empty demandRef) |
capacity-required | 400 | written directly by the PUT /bins/{binId} handler when capacity is omitted |
capacity-out-of-range | 422 | written directly by the PUT /bins/{binId} handler when capacity exceeds int32 |
malformed-request-body | 400 | written directly when a request body is not valid JSON |
internal-error | 500 | anything unmapped |
The domain never knows about any of this. It returns typed errors; the inbound adapter is the only layer that translates them. See ADR 0005.
DTOs never leak domain types
Request and response bodies are adapter-local structs in
internal/adapters/inbound/http/dto.go. A stockUnitResponse is not a
stock.StockUnit; a reservationResponse is not a reservation.Reservation.
That indirection is what lets the domain model evolve without breaking the wire
contract, and it is enforced by the arch-go fitness tests.
Authentication
None. No route — REST or MCP — is authenticated at the application layer,
and apis/openapi.yaml declares no security schemes. A static-bearer-key
layer was adopted in ADR 0014 and
removed again by
ADR 0015. In the local cluster the
API is reached through Kong at http://localhost:8000/api/inventory-storage,
which does not add authentication either.