Skip to content
Toolkit

ADR-0146 — A parameter the document declares is one the handler reads

Status: Accepted · Date: 2026-08-31 · Supersedes: —

Context

ADR-0145 measured shared/contracts/openapi.yaml's operations against the router: that each one exists, and that it is reached with the credential the router demands. It said nothing about what a caller may send, and documenting the four AI collection reads found out why that matters.

The document declares one page-size parameter, per_page. Forty-one handler call sites read results_per_page, and queryParamInt(r, "results_per_page", 25) does not read per_page — so a client that sends the documented name is served the default 25, with no error, on the flagship list endpoints: GET /api/v1/links, /api/v1/biolinks, /api/v1/qr-codes and the admin user list.

One parameter over, the failure is total rather than partial. GET /api/v1/statistics declares a range with five values — today, week, month, year, all — and StatisticsHandler.GetUserStats reads no query string at all: it answers whole-account totals from a five-minute cache. Every value of that parameter has always returned the same numbers, and a caller drawing a weekly figure from it drew the lifetime one.

This is ADR-0144's finding on the request side. There, a property named correctly and typed wrongly passed a gate that compared names; here, a parameter documented and read by nobody passes a gate that compares operations. In both cases the document is plausible and wrong, which is worse for a generated client than being obviously incomplete: the method exists, the argument is accepted, and the server ignores it.

Decision

check:contract-paths gains rule P5: every query parameter a documented operation declares is read by the handler the router registers for it.

The handler is resolved the way the router names it — someHandler.Method, with someHandler built by a handlers.New… in main.go — and the read is taken from the handler package rather than from the method body alone. A read is rarely local: the page size arrives through queryParamInt, and the gate grant through two helpers and a package constant (r.URL.Query()[GateGrantParam]). So the reader follows calls within handlers to a depth of three and resolves a constant to its string. Without that, seven public-resource operations that correctly document grant would have failed, and a gate whose false positives must be argued away is a gate people delete.

It reads names and never values. What a parameter does is the handler's, and a gate that checked the five values of an enum would be a second implementation of the endpoint.

One direction only. A parameter the handler reads and the document does not declare is a gap — the caller is not misled, only under-served — and it is left to a later slice; page and results_per_page are undeclared on many list routes still. A parameter the document declares and nothing reads is a lie, and P5 refuses it with no ledger escape, for C4 and C5's reason.

The five live failures are corrected in this commit, on the document's side. The four page-size declarations now name results_per_page, through a second component parameter that says in as many words that it is a spelling and not a synonym — renaming the server's parameter is a wire change and belongs under /api/v2/, never in place. The statistics range is removed, and the operation now says what it actually serves.

Consequences

A documented parameter is now a claim the build checks. The next one added to the document fails until a handler reads it, which is the same shape as ADR-0089's rule for enforcement: a control is unenforced until a named serving path reads it.

Four routes' page size is documented truthfully for the first time, and the statistics endpoint stops advertising a window it never had. No served byte moves in either case: the corrections are all on the document, because the router is the truth.

The gate now reads the handler package, which is a wider dependency than the router alone. It is bounded on purpose — a depth of three, names only, and a handler it cannot resolve is counted and reported rather than passed in silence.

Watched failing twice beyond ADR-0145's six: a corrected page size put back to the name the route does not read, and a parameter (sort_order) no handler anywhere reads added to a documented operation.

Source: docs/decisions/0146-a-parameter-the-document-declares-is-one-the-handler-reads.md

Library