Repository navigation
fix: send exploded form arrays as repeated keys in client form bodies - #2677
Merged
mromaszewicz merged 1 commit intoNov 20, 2026
Merged
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Contributor
[Medium impact] The PR appears safe to merge; the previous compilation issue is fixed, and no new actionable issues were found. SummaryThe PR sends qualifying exploded form arrays as repeated keys in generated clients and initiators.
Reviews (2) · Last reviewed commit: "fix: send exploded form arrays as repeat..." · Reviewed by Greptile |
For application/x-www-form-urlencoded request bodies the client always called runtime.MarshalForm(body, nil), so the spec's encoding never reached the runtime and an array was sent with indexed keys (topic[0]=a&topic[1]=b) even when it declared style: form, explode: true, which serializes as repeated keys (topic=a&topic=b). Servers which read repeated keys saw no value at all. The client now passes that one encoding through: an array of primitives which declares the form style, explode: true, or both, and nothing to the contrary. Runtime v1.9.1 serializes it as repeated keys, which generated servers already bind the same as indexed keys. Every other declared encoding is still ignored, as before. Generated servers bind form bodies without their encodings, so honoring the rest on the client alone would break clients and servers generated from the same spec. Doing both sides is tracked in oapi-codegen#2676. Bodies with no such encoding generate exactly the code they did. Fixes oapi-codegen#2604 Co-Authored-By: Claude Fable 5.2 <[email protected]>
mromaszewicz
force-pushed
the
fix/client-form-encoding
branch
from
November 20, 2026 16:54
6a96104 to
8d53f41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2604. Depends on runtime v1.9.1 (oapi-codegen/runtime#187), which this bumps in
internal/testandexamples.Problem
For
application/x-www-form-urlencodedrequest bodies, the client always calledruntime.MarshalForm(body, nil), so the spec'sencodingnever reached the runtime. An array was sent with indexed keys (topic[0]=a&topic[1]=b) even when it declaredstyle: form, explode: true, which serializes as repeated keys (topic=a&topic=b). A server which reads repeated keys saw no value at all.Change
The client now passes one declared encoding through to
MarshalForm: an array of primitives in the explodedformstyle. For the spec in #2604 the request builder becomes:The encodings are built inside a function literal so that the
explodevariable cannot collide with a path parameter of the same name, which is an argument of the request builder. (new(true)is not an option: the net/http output is tagged//go:build go1.22.)A property qualifies when all of these hold:
style: form,explode: true, or both, and nothing to the contrary.formis the default style and explodes by default, sostyle: formalone andexplode: truealone both count. An encoding which declares neither does not.contentType.x-go-typeon the array or its items, nooneOf/anyOf/allOfitems, and notformat: binaryorbyte.The property is looked up on the body schema and through its
allOfmembers, so referenced and composed bodies work. The same change is made ininitiator.tmplfor webhook and callback initiators.Why only this encoding
Generated strict servers bind form bodies with
runtime.BindForm(&body, form, nil, nil), without encodings. Repeated keys are the only styled serialization that path reads back the same as the indexed keys the client writes otherwise. Honoring the rest on the client alone (explode: false,spaceDelimited,pipeDelimited, styled objects,contentType) would break clients and servers generated from the same spec, so those are still ignored exactly as before. Doing both sides properly is tracked in #2676.What does not change
make generatechanges no existing generated file.What does change, beyond the keys
For the arrays which qualify, values are now formatted as query parameters are, rather than with
fmt.Sprint. For most values that is identical. Two cases differ, both for the better and both still parsed by generated servers:1000000rather than1e+06.date-timeitems are written as RFC 3339 rather than Go'stime.Time.String()format.Code generated by this version still compiles against an older runtime, which ignores the style, so the fix only takes effect with runtime v1.9.1 or later.
Tests
internal/test/bodies/form_encodinggenerates a client and a strict net/http server from one spec and sends real requests between them, checking both the body on the wire and what the server bound:$refbody whose array comes from anallOfmember.explode: false,pipeDelimited,deepObject,contentType, arrays of objects, objects, a name which is not a property) is unchanged on the wire and still binds.explodestill compiles and round-trips.The initiator template gets the identical change but has no form-body fixture of its own.
🤖 Generated with Claude Code