Skip to content

Parse and validate referenced array query parameters like inline ones - #167

Merged
cubahno merged 1 commit into
mainfrom
ig/fix-ref-array-query-param
Oct 8, 2026
Merged

cubahno merged 1 commit into
mainfrom
ig/fix-ref-array-query-param

Conversation

@cubahno

@cubahno cubahno commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

An array query parameter declared under components/parameters and used through $ref was parsed as a single value. The operation only knew the parameter's alias name (type Terms = []string), not its items, so the handler fell back to runtime.ParseString[Terms] on the first value, which returns nil for a slice without an error.

The service got nil for ?term=one&term=two, and since an alias can't have a Validate() method, item constraints like maxLength were never checked either. A parameter whose schema is a $ref to an array component schema was parsed the same way, though that type's own Validate() still ran.

What changes

  • The handler reads every value of an array query parameter declared with a named type and parses it by the items, as it already did for an inline array: ?term=one&term=two gives ["one", "two"], and an item that doesn't parse as the item type is a 400. This covers a referenced component parameter, a component parameter whose schema references an array schema, and an inline parameter that does.
  • For a component parameter with an inline array schema, the query struct's Validate() checks each item, since the alias has no method of its own. ?term=one&term=toolong against maxLength: 3 is now a 400 and doesn't reach the service.
  • A parameter whose schema references an array component schema keeps calling that type's Validate(), so its minItems/maxItems stay enforced.
  • Inline array parameters and all other parameters generate the same code as before. Across 35 real-world specs with referenced array query parameters, only these parsing and validation blocks changed, and the output builds.
  • runtime.ParseString still returns the zero value for a type it can't parse. Failing on slices instead would turn every request carrying a path or header array parameter into a 400, since those values aren't split into items yet.
  • For custom templates: ParameterDefinition.ArraySchema returns the schema of the slice type a parameter is declared with, looking through a named type. The handler's query parsing uses it instead of .Schema.ArrayType, which stays unset for a parameter declared with a named array type such as TagList.

Fixes #163

@cubahno
cubahno marked this pull request as ready for review October 8, 2026 11:03
@cubahno
cubahno merged commit 7569ca8 into main Oct 8, 2026
3 checks passed
@cubahno
cubahno deleted the ig/fix-ref-array-query-param branch October 8, 2026 11:04
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.

Referenced array query parameters use scalar parsing, discard values, and bypass item validation

1 participant