Skip to main content

API Reference

This service exposes two contracts, both kept as source-of-truth artefacts in the repository and both linted by Spectral in CI:

ContractFileRendered here
REST (synchronous)apis/openapi.yaml — OpenAPI 3.0.3REST API — generated directly from the spec
Events (asynchronous)apis/asyncapi.yaml — AsyncAPI 2.6.0Events

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.

MethodPathOperationTagSuccessErrors
GET/healthzgetHealthzHealth200—
GET/readyzgetReadyzHealth200503
POST/stock-receiptsreceiveStockStock202400 409 422 500
POST/stowagesstowStockStock201400 404 409 422 500
POST/reservationsreserveStockReservations201400 409 422 500
GET/reservations?demandRef=getReservationsByDemandRefReservations200 ({items,nextCursor})400 500
DELETE/reservations/{id}revokeReservationReservations204404 409 500
POST/reservations/{id}/pick-confirmationsconfirmPickReservations204400 404 409 500
GET/inventory/{sku}/usablegetUsableInventoryInventory200400 500
PUT/bins/{binId}registerBinBins200 / 201400 409 422 500
GET/bins/{binId}getBinBins200404 500
POST/bins/{binId}/cycle-countsrunCycleCountBins200400 404 409 422 500
PUT/products/{sku}/classificationclassifyProduct (retired, ADR 0034)Products—410 500
GET/products/{sku}/classificationgetProductClassification (deprecated, local copy)Products200404 500
GET/reports/flow-accuracygetFlowAccuracyReportReports200400 500
GET/reports/flow-accuracy/freshnessgetFlowAccuracyFreshnessReports200500

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:

CodeUsed forExample
200 OKA read, or a command whose result is the response bodyGET /inventory/{sku}/usable; POST /bins/{binId}/cycle-counts returns the reconciliation result
201 CreatedA new addressable resource, with a Location headerPOST /stowages → Location: /stock/{id}; POST /reservations → Location: /reservations/{id}
202 AcceptedAccepted, but no addressable resource exists yetPOST /stock-receipts — a staged receipt has no id and no GET route; the StockUnit is created later, at stow
204 No ContentA state transition with nothing useful to returnrevoke, confirm-pick
400 Bad RequestMalformed or missing inputempty SKU, empty bin id, unparseable JSON
404 Not FoundThe addressed resource does not existunknown reservation, unknown bin
409 ConflictWell-formed and addressable, but conflicts with current statebin full, reservation exceeds usable, reservation already resolved, reservation expired
422 Unprocessable EntityWell-formed but semantically invalid valuesquantity ≤ 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"
}
  • type is a stable, unique URI per error category. It is an identifier — it does not have to resolve to a page.
  • title is a fixed human string for the category; safe to switch on for display, though type is the machine-readable key.
  • detail is the dynamic message from the underlying typed error.
  • instance is 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 slugStatusRaised by
stock-unit-not-found404usecases.ErrStockUnitNotFound
bin-not-found404usecases.ErrBinNotFound
reservation-not-found404usecases.ErrReservationNotFound
product-classification-not-found404usecases.ErrProductClassificationNotFound
empty-sku400shared.ErrEmptySKU
empty-bin-id400shared.ErrEmptyBinID
stow-requires-item-and-location400stock.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-tag400product.ErrUnknownHandlingTag
unknown-temperature-class400product.ErrUnknownTemperatureClass
no-handling-tags400product.ErrNoHandlingTags
temperature-class-required400product.ErrTemperatureClassRequired
temperature-class-not-applicable400product.ErrTemperatureClassNotApplicable
duplicate-handling-tag400product.ErrDuplicateHandlingTag
invalid-dot-hazard-class400product.ErrInvalidDOTHazardClass
dot-hazard-class-not-applicable400product.ErrDOTHazardClassNotApplicable
negative-quantity422shared.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-quantity422shared.ErrZeroQuantity — a quantity ≤ 0 on receive, stow, reserve and relocate (NewPositiveQuantity)
invalid-bin-capacity422location.ErrInvalidCapacity
bin-full409location.ErrBinFull
capacity-below-occupancy409location.ErrCapacityBelowOccupancy (PUT /bins/{binId}, ADR 0025)
release-exceeds-occupancy409location.ErrReleaseExceedsOccupancy
insufficient-usable409usecases.ErrInsufficientUsable, stock.ErrInsufficientUsable
insufficient-reserved409stock.ErrInsufficientReserved
unit-unlocated409stock.ErrUnitUnlocated
reservation-already-resolved409reservation.ErrAlreadyResolved
reservation-expired409reservation.ErrExpired
reservation-no-allocations409reservation.ErrNoAllocations
hazmat-zone-required409usecases.ErrHazmatZoneRequired
temperature-class-mismatch409usecases.ErrTemperatureClassMismatch
location-classification-unavailable409usecases.ErrLocationClassificationUnavailable
hazmat-class-incompatible409usecases.ErrHazmatClassIncompatible
concurrent-modification409usecases.ErrConcurrentModification — a version-guarded Save lost an optimistic-concurrency race (ADR 0019); re-fetch and retry
counted-quantity-required400written directly by the POST /bins/{binId}/cycle-counts handler when countedQuantity is omitted
idempotency-key-required400written by the RequireIdempotencyKey middleware (ADR 0018)
idempotency-key-invalid400written by the RequireIdempotencyKey middleware: not 1-128 printable ASCII characters (ADR 0049)
idempotency-key-reused409written by the RequireIdempotencyKey middleware (ADR 0018, ADR 0049; was 422)
invalid-limit400written by the paginated collection handlers: limit is not an integer in 1..500 (ADR 0049)
invalid-cursor400written by the paginated collection handlers: cursor does not decode (ADR 0049)
invalid-report-query400written by the reports handlers (GET /reports/flow-accuracy)
report-store-error500written by the reports handlers when the read model fails
missing-demand-ref400written directly by the GET /reservations and POST /reservations handlers (empty demandRef)
capacity-required400written directly by the PUT /bins/{binId} handler when capacity is omitted
capacity-out-of-range422written directly by the PUT /bins/{binId} handler when capacity exceeds int32
malformed-request-body400written directly when a request body is not valid JSON
internal-error500anything 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.