Skip to main content

API Reference

This service exposes three contracts, kept as source-of-truth artefacts in the repository and linted by Spectral (the api-lint CI job):

ContractFileRendered here
REST (synchronous, cmd/order)apis/openapi.yaml — OpenAPI 3.0.3REST API — generated directly from the spec
Reports REST (read-only, cmd/order-reports)apis/openapi-reports.yaml — OpenAPI 3.0.3 (ADR 0039)Reports API — generated directly from the spec
Kafka (asynchronous)apis/asyncapi.yaml — AsyncAPI 2.6.0Not rendered on this site; see Domain Events

The REST pages under REST API and Reports API Reference are generated from the two OpenAPI files by docusaurus-plugin-openapi-docs (npm run clean-api-docs:all && npm run gen-api-docs:all, checked by the docs-api-drift CI job). They are not hand-transcribed, so they cannot drift from the specs the service ships.

Reports endpoint matrix (cmd/order-reports, default :8092)​

MethodPathOperationSuccessErrors
GET/healthzgetReportsHealthz200 {"status":"ok"}—
GET/reports/funnelgetOrderFunnelReport200 {"rows":[...]}400 invalid-report-query, 500 report-store-error
GET/reports/funnel/freshnessgetOrderFunnelReportFreshness200 {"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.

Endpoint matrix​

internal/adapters/inbound/http/server.go registers 8 routes; 7 of them are declared in apis/openapi.yaml (GET /readyz is not — see the note below the table). There is no /orders/{id}/allocate any more: allocation and release are folded into POST /orders and the allocation-retries transition resource (ADR 0005). The routes follow the fleet REST API guideline (ADR 0048): nouns, never verbs.

MethodPathOperationTagSuccessErrors
GET/healthzgetHealthzHealth200—
GET/readyz(not in spec)—200 {"status":"ready"}503 {"status":"not_ready"} once shutdown starts (ADR 0025)
POST/ordersreceiveOrderOrders201400 409 422 500
GET/orders/{id}getOrderOrders200400 404 500
DELETE/orders/{id}cancelOrderOrders204400 404 409 503 500
POST/orders/{id}/releasesreleaseHeldOrderAllocation200400 404 409 503 500
POST/orders/{id}/allocation-retriesretryAllocationAllocation200400 404 409 503 500
GET/planned-capacitygetPlannedCapacityPlannedCapacity200400 500

GET /planned-capacity is registered only when PLANNED_CAPACITY_CONSUMER_GROUP is set (ADR 0031). Every POST (/orders, /orders/{id}/releases, /orders/{id}/allocation-retries) is wrapped by the Idempotency-Key middleware (ADR 0023, ADR 0048) whenever the service runs with DATABASE_URL: a missing key is 400 idempotency-key-required, a key that is not 1-128 printable ASCII characters is 400 idempotency-key-invalid, the same key with a different method, path or body is 409 idempotency-key-reused, and a replay returns the stored response with the header Idempotency-Replayed: true. The header is declared as the IdempotencyKey parameter in apis/openapi.yaml; DELETE /orders/{id} is idempotent by method and takes no key. A version-guard conflict on any write (ADR 0024) is 409 concurrent-modification. GET /planned-capacity is a bounded read model for one site (x-pagination-exempt: report), not a paged collection.

Status-code conventions​

CodeUsed forExample
200 OKA read, or a command whose result is the response bodyGET /orders/{id}; POST /orders/{id}/allocation-retries returns the order after the pass
201 CreatedA new addressable resource, with a Location headerPOST /orders → Location: /orders/{id}
204 No ContentA state transition with nothing useful to returnDELETE /orders/{id}
400 Bad RequestMalformed or missing inputempty SKU, unparseable JSON
404 Not FoundThe addressed resource does not existunknown order
409 ConflictWell-formed and addressable, but conflicts with current stateorder already released (cancel), order not held (release), no backordered lines (retry), concurrent modification
422 Unprocessable EntityWell-formed but semantically invalid valuesquantity ≤ 0; a line ineligible for its resolved path; a held order with allowPartialShipment: true
503 Service UnavailableA downstream Supplier could not be reached, answered ambiguously, or is wired in permissive (no-op) modeany non-409 failure from inventory-storage during retry/release/cancel

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." The 409 / 503 split matters just as much here: 409 means this context's own state disagrees with the request; 503 means a Supplier could not be trusted to answer, never papered over with a fabricated success (BR2).

Errors: RFC 7807 Problem Details​

Every error response uses application/problem+json, the same shape the other services in this platform emit:

{
"type": "https://errors.order-management.warehouse-systems.dev/order-already-released",
"title": "Order already has released lines and can no longer be cancelled",
"status": 409,
"detail": "order already has released lines and can no longer be cancelled",
"instance": "/orders/ord-a1b2c3d4-0000-0000-0000-000000000001"
}
  • 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.
  • detail is the dynamic message from the underlying typed error.
  • instance is the request path.

Problem-type catalog​

type slugStatusRaised by
order-not-found404order id does not exist
empty-order-id400the path's order id is empty
empty-sku400a line's SKU is empty
order-without-lines400the order has no lines
unknown-process-path400the resolved path is not active in the process-path catalogue (ADR 0013)
malformed-request-body400the body is not valid JSON, or a field is explicitly null
idempotency-key-required400a POST without an Idempotency-Key header (ADR 0023, ADR 0048)
idempotency-key-invalid400an Idempotency-Key that is not 1-128 printable ASCII characters (ADR 0048)
invalid-query-parameter400GET /planned-capacity without site, or a non-RFC 3339 from
non-positive-quantity422a line's quantity is not greater than zero
line-ineligible-for-resolved-path422a line's product attributes are not eligible for any active path (ADR 0016/0021)
held-order-must-be-ship-complete422releaseOnAllocation: false combined with allowPartialShipment: true (ADR 0020)
order-already-released409CancelOrder when any line is Released or Shipped (BR6)
no-backordered-lines409RetryAllocation on an order with nothing backordered
order-not-held409ReleaseHeldOrder on an order that was not held at intake (ADR 0020)
concurrent-modification409the order's version changed between read and save (ADR 0024)
idempotency-key-reused409the same Idempotency-Key sent with a different method, path or body (ADR 0023, ADR 0048); distinguishable from the business 409s by this type
downstream-not-configured503a Supplier client is running in permissive (no-op) mode
downstream-unavailable503inventory-storage failed (transport error, timeout, open circuit breaker, unexpected status) on POST /orders/{id}/allocation-retries, POST /orders/{id}/releases or DELETE /orders/{id} (ADR 0003, ADR 0025)
internal-error500anything unmapped

The reports binary (cmd/order-reports) uses its own two types, invalid-report-query (400) and report-store-error (500).

problemFor in internal/adapters/inbound/http/errors.go also maps line-state guard errors (order-line-not-found 400; order-line-already-allocated, order-line-not-pending, order-line-not-backordered, order-line-not-allocated, no-allocated-lines, promise-date-not-set 409) and insufficient-stock (503); the current use cases catch or never return most of these on their HTTP paths (the per-line 409 from inventory-storage becomes a Backordered line, not an error).

There is deliberately no problem type for BR3 (ship-complete). A ship-complete order whose release is blocked because a line is unallocated is a hold, not an error (ADR 0003): POST /orders answers 201, and POST /orders/{id}/allocation-retries and POST /orders/{id}/releases answer 200, each with the order Backordered and nothing released.

The domain never knows about any of this. It returns typed errors; the inbound adapter is the only layer that translates them.

DTOs never leak domain types​

Request and response bodies are adapter-local structs in internal/adapters/inbound/http/dto.go. An orderResponse is not an order.Order. That indirection is what lets the domain model evolve without breaking the wire contract.

Authentication​

None. The spec declares no security scheme at all: this service's REST and MCP surfaces are reachable with no Authorization header (see ADR 0012, which removed the static-bearer layer ADR 0011 had adopted).