Skip to content

fix: report binding errors for exploded form objects - #195

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/exploded-object-bind-errors
Nov 22, 2026
Merged

mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/exploded-object-bind-errors

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Part of #193 (defect 2 of 2).

Problem

When a property of a style: form, explode: true object query parameter is present but can not be bound, bindParamsToExplodedObject returns the error together with fieldsPresent == false. Both callers (BindQueryParameterWithOptions and BindRawQueryParameterWithOptions) tested fieldsPresent before err, so the error was discarded and the parameter was handled as though it were absent:

  • an optional parameter was silently left unbound, valid properties included, so ?cursor=xyz&limit=abc reached the handler with no filters at all;
  • a required parameter produced a misleading RequiredParameterError.

This dates back to the "Fix optional binding" change in 2022. The comment above the check has always read "If no fields were set, and there is no error", so this restores the intended behavior.

Fix

Check err first in both callers.

Behavior change

For an optional exploded form object, a request with a malformed property now fails with a binding error (a 400 in generated servers) where it previously succeeded with the whole parameter dropped. The affected inputs are:

  • a primitive property that does not parse, such as limit=abc for an integer;
  • a primitive property specified more than once;
  • a property of a type the binder can not handle at all.

This matches what already happens for the same malformed value in a parameter that is not an object. Required parameters already failed, and now fail with an accurate message. Worth a line in the release notes.

The companion PR for the first defect in #193 (array properties) is independent of this one and the two merge cleanly in either order.

🤖 Generated with Claude Code

When a property of a form style, exploded object query parameter was
present but could not be bound, bindParamsToExplodedObject returned the
error along with fieldsPresent=false. Both callers tested fieldsPresent
first, so the error was discarded and the parameter was handled as
though it were absent: an optional parameter was silently left unbound,
valid properties included, and a required one produced a misleading
RequiredParameterError.

Check the error first, in BindQueryParameterWithOptions and
BindRawQueryParameterWithOptions. A malformed property, such as
`limit=abc` for an integer or a primitive specified twice, now fails
the request the way it does for a parameter which is not an object.

Part of oapi-codegen#193

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner November 22, 2026 23:47
@mromaszewicz mromaszewicz added bug Something isn't working ☢️ breaking change labels Nov 22, 2026
@mromaszewicz
mromaszewicz merged commit 9b7381c into oapi-codegen:main Nov 22, 2026
10 checks passed
@mromaszewicz
mromaszewicz deleted the fix/exploded-object-bind-errors branch November 22, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ breaking change bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant