Skip to content

feat(api): typed query parameters (#865) - #1215

Merged
athvin merged 2 commits into
mainfrom
issue/865-typed-query-params
Nov 25, 2026
Merged

athvin merged 2 commits into
mainfrom
issue/865-typed-query-params

Conversation

@athvin

@athvin athvin commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #865

🚧 Claimed by an agent session — 2026-11-25T07:02:46Z, session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac.
The claim is this open draft PR: closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

All 27 Query<HashMap<String, String>> extractors become one named struct per handler, and er-api-spec derives their fields as documented in: query parameters. The internal document now lists 86 query parameters (75 public): cursors, limits and every filter. It listed none before, not even the two structs that were already typed. A Query<HashMap…> now fails generation.

Why

#857 / #1013: an API with undocumented cursors and filters is not an integration contract.

Proof

  • make check: 1,164 passed, 0 failed.
  • er-server --tests against Postgres: 396 passed.
  • Frontend tsc --noEmit is clean against the regenerated schema.d.ts.
  • Hand-checked three shapes:
    • reviews (cursor page): cursor, limit, max_probability, min_probability, reason, status
    • duplicates (filter bag): all 12 keys
    • assertions (single flag): cursor, include_retracted, limit

Risk & rollback

Behaviour is preserved by construction, with one stated exception: a repeated key (?tag=a&tag=b), which the bag resolved to the last value, is now a 400. No BFF route sends one to a converted handler. Rollback: git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac · 2026-11-25T07:54:09Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  • er-api-spec: Parameter gains location, required and description. parameters() reads Query<Struct> through struct_fields, which now captures /// docs. Query<HashMap> is an error.
  • openapi.rs renders query parameters (ParameterIn::Query, required from the field, description from the doc).
  • 27 handlers: a struct per handler with all fields Option<String>. params.get("k") becomes params.k.as_ref() (the same Option<&String>), or .as_deref() where it was mapped to &str.
  • Tests: derivation and refusal in er-api-spec; query_param_tests for missing, unknown, empty, non-numeric and duplicate keys across all 27.
  • The api-contract skill is updated.

Discoveries

  • Fields stay Option<String> on purpose. Typing limit as i64 would turn ?limit=abc's silent fallback into a 400, which violates "no type changes". The doc text gives each parameter's real format instead.
  • Rewriting through field access makes a missed key a compile error. The bag would have silently returned None. Two closures took key names (duplicates, reviews) and now take values.
  • The audit feeds share audit_feed but differ by org. The global feed projects to AuditIndexQuery, so the org feed doesn't document a parameter it ignores.
  • Repeated keys in the frontend never reach a converted route. Repeated key= goes to /records, which reads the raw query and is unconverted. Repeated review_id= is answered BFF-locally.

Measurements

Files

rust/crates/er-api-spec/src/{manifest.rs,operations.rs,operations/requests.rs,operations/tests.rs}, rust/crates/er-server/src/{lib.rs,openapi.rs}, frontend/src/lib/api/{openapi.json,openapi.public.json,schema.d.ts}, .claude/skills/api-contract/SKILL.md

All 27 Query<HashMap<String, String>> extractors are now one named
Deserialize struct per handler, and er-api-spec derives their fields as
documented in: query parameters (each field's /// doc is the
description; required only when neither Option nor serde(default)).
The internal document now lists 86 query parameters (75 public),
including cursors, limits and every filter. Before this, it listed none,
not even for the two structs that were already typed.

Behaviour is preserved by construction. Every new field is
Option<String>, and each params.get("k") became params.k.as_ref(), the
same Option<&String> type, so the handlers' lenient parsing is
untouched and a key missing from its struct fails to compile rather than
reading None. The two closures that took key names (duplicates, reviews)
now take values. audit_feed takes AuditIndexQuery, which the global feed
projects to (it has org; the org feed does not). golden_records_page
takes GoldenRecordsListQuery.

One stated change: a repeated key (?tag=a&tag=b), which the bag resolved
to the last value, is now a 400. No BFF route sends one to a converted
handler (repeated key= goes to /records, which reads the raw query;
repeated review_id is BFF-local).

A Query<HashMap…> now fails generation, so the untyped bag cannot return.
Tests: er-api-spec covers derivation and the refusal; query_param_tests
covers missing/unknown/empty/non-numeric for all 27 structs and pins the
duplicate-key change. The api-contract skill is updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

@athvin
athvin marked this pull request as ready for review November 25, 2026 07:18
@athvin
athvin merged commit d948bde into main Nov 25, 2026
46 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 25, 2026 07:23 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — d0b06346 Deployed Nov 25, 2026 by athvin via remove closed PR previews #33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed query parameters: replace the 26 Query<HashMap> extractors with named structs

2 participants