Repository navigation
fix: honour style and explode in MarshalForm encodings - #187
Merged
mromaszewicz merged 1 commit intoNov 20, 2026
Merged
Conversation
MarshalForm only read ContentType from a property's encoding, so an array was always written with indexed keys (topic[0]=a&topic[1]=b), even when the encoding declared style: form, explode: true, which serializes as repeated keys (topic=a&topic=b). A property whose encoding sets Style or Explode is now serialized as a query parameter of that style would be: form, spaceDelimited and pipeDelimited repeat the key when exploded and write one delimited value otherwise, and deepObject is the bracketed default. Explode defaults to true for form and false otherwise, as in the specification. Properties with no encoding, or one that sets neither field, are unchanged. Also fix the ContentType branch, which returned "unsupported encoding" for application/json too and marshaled the reflect.Value rather than the value it holds. Fixes oapi-codegen#186 Refs oapi-codegen/oapi-codegen#2604 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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 #186. Runtime half of oapi-codegen/oapi-codegen#2604.
Problem
MarshalFormonly readContentTypefrom a property'sRequestBodyEncoding, so an array was always written with indexed keys (topic[0]=a&topic[1]=b), even when the encoding declaredstyle: form, explode: true, which serializes as repeated keys (topic=a&topic=b). Servers that read repeated keys saw no value at all.Change
A property whose encoding sets
StyleorExplodeis now serialized the way a query parameter of that style would be:["a", "b"]formtrue(default)topic=a&topic=bformfalsetopic=a,bspaceDelimitedfalse(default)topic=a bpipeDelimitedfalse(default)topic=a|bdeepObjecttopic[0]=a&topic[1]=b(the existing output)Explodedefaults to true forformand false for the other styles, as in the specification.Styledefaults toformwhen onlyExplodeis set.name=k,v,k,v.simple,labelandmatrixare rejected, as are arrays of objects under a style other thandeepObject.StylenorExplode, keeps the bracketed output. Generated code passesniltoday, so existing callers are unaffected.styleStructandstyleMaphave their field-flattening loops extracted intostructFieldDictandmapFieldDictso the form path can share them; their behaviour is unchanged.Also fixed: the
ContentTypebranchThe
application/jsonbranch returnedunsupported encoding, only application/json is supportedeven forapplication/json, since the error return wasn't in anelse, and it marshaled thereflect.Valuerather than the value it holds. It now writes the JSON and carries on, and skips nil optional properties. This has to work before the generator can pass encodings through.Notes
BindFormis untouched. It treats an unsetExplodeas false, which differs from the default here, but generated servers pass itnilencodings and the default binding already accepts repeated keys,name[]andname[i].ContentTypestill errors, as before.🤖 Generated with Claude Code