Skip to content

fix: bind array properties of exploded form objects - #194

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

mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/exploded-object-array-fields

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Part of #193 (defect 1 of 2). Originally reported as oapi-codegen/oapi-codegen#476.

Problem

An array property of a style: form, explode: true object query parameter repeats its name once per element, the same as a top-level exploded array:

GET /users?orderBy=foo&orderBy=bar

bindParamsToExplodedObject treated every property as a primitive, so this could never bind into

type QueryFilters struct {
	Limit   *int      `json:"limit,omitempty"`
	OrderBy *[]string `json:"orderBy,omitempty"`
}

More than one value was rejected as field 'orderBy' specified multiple times, and a single value failed because a string can not be bound to a slice.

Fix

Slice fields, and pointers to slices, now bind one element per value, through the same bindSplitPartsToDestinationArray used for top-level exploded arrays. Commas are not delimiters here, matching the top-level behavior.

Slices that bind from a single string are left on the existing path: []byte, and types that parse themselves through Binder or encoding.TextUnmarshaler.

Compatibility

Additive only. Every input whose result changes previously failed to bind; nothing that binds today binds differently.

The companion PR for the second defect in #193 (binding errors being discarded by the callers) is independent of this one and the two merge cleanly in either order.

🤖 Generated with Claude Code

An array property of a form style, exploded object query parameter
repeats its name once per element (`orderBy=foo&orderBy=bar`), the same
as a top level exploded array. bindParamsToExplodedObject treated every
property as a primitive, so more than one value was rejected as
"specified multiple times", and a single value failed because a string
can not be bound to a slice.

Slice fields, and pointers to them, now bind one element per value.
Byte slices and slices which parse themselves through Binder or
encoding.TextUnmarshaler keep binding from a single string.

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 the bug Something isn't working label Nov 22, 2026
@mromaszewicz
mromaszewicz merged commit e3e761a into oapi-codegen:main Nov 22, 2026
10 checks passed
@mromaszewicz
mromaszewicz deleted the fix/exploded-object-array-fields branch November 22, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant