Skip to content

openapi3filter: prefer non-empty value for repeated scalar query params#1231

Merged
fenollp merged 2 commits into
getkin:masterfrom
sonnemusk:fix/scalar-query-prefer-nonempty
Jul 23, 2026
Merged

openapi3filter: prefer non-empty value for repeated scalar query params#1231
fenollp merged 2 commits into
getkin:masterfrom
sonnemusk:fix/scalar-query-prefer-nonempty

Conversation

@sonnemusk

Copy link
Copy Markdown
Contributor

What

When a scalar query parameter is repeated and the first value is empty, decode the first non-empty occurrence instead of always taking values[0].

Why

With allowEmptyValue: true, an empty first value short-circuits schema validation. That made order-dependent results:

  • ?dateOfBirth=&dateOfBirth=not-a-date was accepted
  • ?dateOfBirth=not-a-date&dateOfBirth= was rejected

A single empty value still works as before (#1228 / #1134).

Fixes #1230.

Test

  • TestIssue1230
  • existing TestIssue1134

… params

When a scalar query parameter is supplied multiple times and the first
value is empty, decode the first non-empty occurrence so allowEmptyValue
cannot skip schema validation of a later invalid value (getkin#1230).
Comment thread openapi3filter/req_resp_decoder.go Outdated
Address review: keep the repeated-scalar preference logic with a short
human comment only.
@sonnemusk

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  • Dropped the verbose comment.
  • On allowEmptyValue: DecodePrimitive only receives the schema, not the parameter, so it cannot gate on parameter.AllowEmptyValue without a wider API change. Preferring the first non-empty repeated value is the right fix for openapi3filter: repeated query param with empty first value bypasses schema validation #1230 either way: with allowEmptyValue: true, a leading "" would otherwise skip schema checks entirely (validate_request.go) and hide a later invalid value; with allowEmptyValue: false, an empty scalar is still validated by the schema when no non-empty sibling exists. Happy to follow up if you want allowEmptyValue threaded into the decoder interface.

@fenollp fenollp changed the title fix(openapi3filter): prefer non-empty value for repeated scalar query params openapi3filter: prefer non-empty value for repeated scalar query params Jul 23, 2026
@fenollp
fenollp merged commit 3e5d7f4 into getkin:master Jul 23, 2026
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.

openapi3filter: repeated query param with empty first value bypasses schema validation

2 participants