Skip to content

Name inline union parameters so they reach the request - #180

Merged
cubahno merged 3 commits into
mainfrom
ig/name-inline-union-params
Oct 29, 2026
Merged

cubahno merged 3 commits into
mainfrom
ig/name-inline-union-params

Conversation

@cubahno

@cubahno cubahno commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

A query parameter whose schema is a union with two or more non-null variants (id | "null" | null, or a nested anyOf) was generated as an anonymous struct holding a json:"-" field.
That field only works because the parent type's generated MarshalJSON merges it back, and an anonymous struct can't have methods.
So it marshaled to {}, form encoding emitted no pairs, and the parameter was silently missing from the URL: no error, and the server returned an unfiltered result. Path and header parameters share the same code path.

What changes
generateParamsTypes gives a parameter schema a named type, with a generated MarshalJSON, when it would otherwise be an anonymous struct with nameless fields. It reuses the needsMarshaler check that object properties already go through.
The type is named <Operation><Query|Path|Headers>_<Param>, e.g. ListWidgetsQuery_ParentID, the same pattern used for parameters with additionalProperties.
The parameter field changes from an anonymous struct to that named type.
Code that built the old anonymous struct literal stops compiling, but that field never produced a value.

Parameters that collapse to a single type (asc | desc | null) are unchanged, and make generate changes no existing example.
New examples/union/anyof-query-params has the reproduction spec from the issue and a test that the value reaches GetQuery() for both the nested and the flattened union.

Fixes #177

@cubahno
cubahno force-pushed the ig/name-inline-union-params branch from ff9c4bf to 97c2f93 Compare October 29, 2026 09:47
@cubahno
cubahno marked this pull request as ready for review October 29, 2026 09:55
@cubahno
cubahno merged commit 3cde09d into main Oct 29, 2026
3 checks passed
@cubahno
cubahno deleted the ig/name-inline-union-params branch October 29, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Query parameters with multi-variant unions generate a dead json:"-" wrapper field — the parameter is silently dropped from requests

1 participant