0039. The reports binary's routes are a contract: apis/openapi-reports.yaml
Status
Accepted — implemented by the change that introduces this record (fleet gap-fix wave 2026-10-12, decision D18).
Extends ADR 0006 (the analytical data
product and its separate cmd/order-reports reader).
Context
ADR 0006 split the Order Funnel & Allocation Health data product into a
writer (cmd/order-projector) and a read-only reader (cmd/order-reports,
default :8092). The reader serves three routes (NewReportsRouter in
internal/adapters/inbound/http/reports_handler.go): GET /healthz,
GET /reports/funnel and GET /reports/funnel/freshness. Other contexts
call them: the console's context-reports page and warehouse-ops-agent
(ORDER_MANAGEMENT_REPORTS_REST_URL).
None of these routes was in any spec. apis/openapi.yaml describes
cmd/order only. The shape lived in a hand-written page
(docs/docs/analytics/order-funnel-report.md) and in the handler's DTOs, so
nothing linted it, nothing rendered it and nothing failed when the handler
and the documentation disagreed. labor-performance already solved the same
problem with a second spec, apis/openapi-reports.yaml, and the fleet chose
that convention for every *-reports binary.
Decision
- A second OpenAPI 3.0.3 file,
apis/openapi-reports.yaml, specifies every route ofcmd/order-reports: operationsgetReportsHealthz,getOrderFunnelReport(queryfrom,torequired RFC 3339;pathIdoptional;granularityoptional, onlyhour) andgetOrderFunnelReportFreshness, theFunnelRowwith all 17 fields the handler emits,Freshness,Healthand the RFC 7807Problemwith the two reports problem types (invalid-report-query400,report-store-error500). Serverhttp://localhost:8092. No security scheme (ADR 0012). It is a description of what already ships: no route, field or status changes. - Linted by the
api-lintCI job with the same.spectral.yamlruleset as the OLTP spec. - Rendered as a generated "Reports API Reference" in the docs site: a
second
docusaurus-plugin-openapi-docsconfig (orderReports, outputdocs/docs/api-reference/rest-reports), withgen-api-docs:all/clean-api-docs:allscripts. Thedocs-api-driftjob regenerates both specs and fails on any difference. - Contract-tested against the real router. Schemathesis (the
contractjob) bootscmd/orderin memory;cmd/order-reportsrefuses to start without an analytical database, so instead two Go tests in thetestjob read the spec:TestReportsContract_RoutesMatchSpecwalks the chi router and fails when a route is served but not specified, or specified but not served.TestReportsContract_ResponsesMatchSpecdrives every documented status of every operation with a stub store and fails on an undeclared status or media type, a missing required property or an undocumented property (rows included).
Consequences
- A new reports route or field fails the build until the spec, and so the generated reference, describe it.
- Consumers (console, ops agent) have a published shape to code against.
- The spec does not prove value semantics (that a counter counts the right event); the analytics store's integration tests and the handler unit tests keep doing that.
gopkg.in/yaml.v3, already in the module graph, becomes a direct (test-only) dependency.
Alternatives considered
- Add the routes to
apis/openapi.yaml. Rejected: that spec describescmd/orderon:8080, and Schemathesis would then call/reports/*on a binary that does not serve them. - Schemathesis against
cmd/order-reportswith a testcontainers Postgres. Rejected for now: it needs the projector's migrations and a container in thecontractjob, for a read-only surface with three GET operations whose inputs the Go tests already cover.