Repository navigation
Conversation
Share the form style defaults with the encoder, preserve legacy indexed keys, and bind JSON to the encoded field. Prepared with OpenAI Codex.
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.
Problem
MarshalFormcan encode repeated or delimited arrays, butBindFormconsumes only the first value and delegates to the query-parameter binder. Some form styles fail to bind. An encoded field also skips indexed or bracketed keys from older clients when its plain key is absent. For anapplication/jsonfield, the decoder writes into the entire destination and returns an unsupported encoding error.Change
Use the same form style defaults and delimiters for reading and writing arrays. Bind repeated values in order, allocate optional typed slices through the existing form binder, and accept the older indexed or bracketed keys when a field has no plain key. Decode JSON values into their own fields and consume already-decoded scalar values directly.
This covers the styled arrays and JSON-valued fields in the runtime work described in oapi-codegen/oapi-codegen#2676. That issue also tracks styled flat objects and generator template changes.
Verification
On upstream
ee84079f0f599e5e82e4f4d81dc167373cb046be, eight array and legacy-input cases and the JSON-field round trip failed.The tests round trip actual URL form representations through
MarshalForm,url.Values.Encode,url.ParseQuery, andBindForm. They cover the supported array styles, defaults, optional integer slices, legacy bracketed input, JSON fields, and special characters in decoded values. An adjacent test checks the existing scalar text unmarshaler path.On Go 1.26.0,
go test -p 4 -json -count=1 ./...passed 716 tests and subtests across two packages. One package had no test files.go vet -p 4 ./...andgofmt -lcompleted without findings.OpenAI Codex prepared the patch, regression tests, and local verification.