Skip to content

webapi-contract: an optional param is present by its own key, not by a sibling it prefixes - #48

Merged
mageshb merged 1 commit into
masterfrom
fix/param-exact-presence
Sep 23, 2026
Merged

mageshb merged 1 commit into
masterfrom
fix/param-exact-presence

Conversation

@mageshb

@mageshb mageshb commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

The presence tests in FromParam (Maybe a, Either a b, lists, Set/MultiSet elements, a sum's constructor) used submap key kvs, a raw byte-prefix lookup, so a sibling key the field's name prefixes made the field "present":

Params Field Before After
pageSize=20 page :: Maybe Int NotFound "page" Nothing
idsFilter=5 ids :: Maybe [Int] Just [] Nothing
innerMost=8 inner :: Maybe Inner NotFound "inner.x" Nothing

Callers renamed fields to dodge it (zenbridge#2241: partnerQualifier for partnerAddressQualifier, multiFileIds for fileIds).

The change: subParams key returns the key itself plus the keys nested under it (key.). The empty key (the top level) returns everything. The record-selector narrowing (submap pfx in GFromParam (M1 S …)) is unchanged: lookups below it are exact.

Branched from 57ea0eb (the commit zenbridge pins; Param.hs is unchanged on master since then). webapi-contract-test: 30/30 pass. The three cases above fail before the change and pass after. Running the suite on GHC 9.6.7 needs allow-newer for the test stanza's tasty/hedgehog bounds; those bounds are untouched here.

🤖 Generated with Claude Code

…a sibling it prefixes

The presence tests in FromParam (Maybe a, Either a b, lists, Set and
MultiSet elements, a sum's constructor) took `submap key kvs`, a raw
byte-prefix lookup: `page :: Maybe Int` saw `pageSize=20` as its own
params, found no `page` and failed NotFound "page"; `ids :: Maybe [Int]`
became `Just []` beside `idsFilter`; `inner :: Maybe Inner` failed
NotFound "inner.x" beside `innerMost`. Callers renamed fields to dodge
it (zenbridge#2241: `partnerQualifier` for `partnerAddressQualifier`,
`multiFileIds` for `fileIds`).

subParams key: the key itself and the keys nested under it (`key.`),
the top level (the empty key) everything. Tests: the three cases above
fail before the change, pass after; round trip unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mageshb
mageshb merged commit 9914a65 into master Sep 23, 2026
0 of 5 checks passed
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.

1 participant