Skip to content

chore(deps): update module github.com/oapi-codegen/runtime to v1.10.0 - #21

Open
renovate[bot] wants to merge 1 commit into
mainfrom
renovate/github.com-oapi-codegen-runtime-1.x
Open

renovate[bot] wants to merge 1 commit into
mainfrom
renovate/github.com-oapi-codegen-runtime-1.x

Conversation

@renovate

@renovate renovate Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
github.com/oapi-codegen/runtime v1.9.1 → v1.10.0 age adoption passing confidence

Release Notes

oapi-codegen/runtime (github.com/oapi-codegen/runtime)

v1.10.0: : RFC 3986 query encoding, and more robust form and parameter binding

Compare Source

This release changes how generated clients encode a space in query parameters, from + to %20, and fixes a batch of long-standing bugs in form body and query parameter binding: panics on malformed form keys, date and time properties that were silently dropped from form bodies, array properties of exploded form objects that never bound, and binding errors that were swallowed. Several of those fixes change what the runtime sends or accepts, so they are listed as breaking changes below, with the opt-out where there is one. No exported API was removed, the minimum Go version and the module's dependencies are unchanged, and nothing needs regenerating: upgrading is a go get.

☢️ Breaking changes at a glance

Change Why we did it Who notices Opt-out
Query parameters encode a space as %20, not + To be more standards compliant Clients runtime.DefaultQueryEncoder = runtime.NetURLQueryEncoder{}
MarshalForm writes a self-marshaling type as its text, ip=192.0.2.1 Bug fixes that required a behavior change Clients sending form bodies to a server on runtime v1.9.1 or earlier runtime.MarshalFormIgnoresTextMarshaler = true
BindForm rejects an indexed array with a gap, and ignores non-canonical indexes Gaps are generally bad input, and accepting them lets a small request allocate a huge array Servers reading form bodies runtime.BindFormAllowsArrayGaps = true, at the cost of that protection
A malformed property of an exploded form object is an error, not a dropped parameter Correctness fix Servers None
Binder is honored on an optional property of an exploded form object Bug fix Servers with their own Binder types None

The opt-outs are package variables. Set them once during program initialization, as they are not safe to change while requests are in flight.

Notable Changes

☢️ Breaking: query parameters encode a space as %20

DefaultQueryEncoder is now RFC3986QueryEncoder where it was NetURLQueryEncoder, so a generated client sends ?q=a%20b where it sent ?q=a+b (#​190, closes #​189). OpenAPI's style: form for query parameters is defined by RFC 6570, which encodes a space as %20. + belongs to application/x-www-form-urlencoded, which is the encoding of form bodies. A server that reads + as a space reads %20 as one too, but strict RFC 3986 servers, OData endpoints among them, reject + with a 400.

Most programs will see no difference. The ones that will are those that compare raw query strings: recorded HTTP fixtures, mocks matched on the exact URL, and request signatures computed over the query. deepObject parameters go through the same encoder. Path parameters and form bodies are unchanged.

To restore the previous encoding:

func init() {
    runtime.DefaultQueryEncoder = runtime.NetURLQueryEncoder{}
}
☢️ Breaking: MarshalForm writes self-marshaling types as text

A type that implements encoding.TextMarshaler is now a single value in a form body, whatever Go type it is made of. A net.IP used to be written as its bytes, ip[0]=192&ip[1]=0&ip[2]=2&ip[3]=1, and is now ip=192.0.2.1 (#​204).

BindForm in this release reads both layouts, but BindForm in v1.9.1 and earlier reads only the indexed one. A client that upgrades ahead of a server which binds such a type from a form body should keep sending the old layout until the server has upgraded:

func init() {
    runtime.MarshalFormIgnoresTextMarshaler = true
}

Times, dates and UUIDs are single values with or without the setting, and so is anything under a property whose encoding declares a style.

☢️ Breaking: BindForm array indexes must run from zero without a gap

BindForm sized an array by the highest index a form named, so the 20-byte body topic[4000000]=a allocated four million elements. Indexes now have to run from 0 without a gap, which keeps an indexed array no longer than the number of keys sent for it (#​204).

  • topic[0]=a&topic[2]=c used to bind ["a", "", "c"]. It is now an error: form array 'topic' has no element at index 1: indexes must run from 0 without gaps.
  • Only an index written the canonical way names an element. topic[01] and topic[-1] are ignored; topic[01] used to add an empty element.

Arrays sent by repeating the key, topic=a&topic=b, are unaffected.

If you have clients that send arrays with gaps, BindFormAllowsArrayGaps accepts them again and leaves the elements a form does not name at their zero value (#​205). Non-canonical indexes are ignored either way.

func init() {
    runtime.BindFormAllowsArrayGaps = true
}

[!WARNING]
With this set, a request decides how much memory your server allocates. Anyone who can send a form body can make BindForm allocate an array of any size with a single short key, until the process runs out of memory. Set it only where every client is trusted, or where something in front of BindForm has already refused such a form.

☢️ Breaking: binding errors in exploded form objects are reported

An object query parameter with style: form, explode: true, the default for query parameters, sends each property as its own key. When one of those was present but could not be bound, the error was discarded and the whole parameter treated as absent (#​195, part of #​193):

  • an optional parameter was left unbound, valid properties included, so ?cursor=xyz&limit=abc reached the handler with no filter at all;
  • a required parameter failed with a misleading query parameter 'filter' is required.

Both now fail with the binding error itself, which is a 400 in generated servers. The inputs affected are a property that does not parse, such as limit=abc for an integer, a primitive property given more than once, and a property of a type the binder can not handle. There is no opt-out: every request that now fails is one whose parameter was being thrown away.

☢️ Breaking: Binder is honored on optional properties

A type that implements runtime.Binder did not have Bind called when it was an optional property of an exploded form object. The destination there is a pointer to a pointer, which never implements the interface, so the type was parsed by the built-in conversion for its kind (#​198, part of #​196). With an integer type whose Bind accepts 50% and rejects anything over 100, 150 was accepted as an optional property and rejected everywhere else.

Bind is now called in both cases. For such a property:

  • a value Bind rejects, but the built-in parser accepted, is now an error;
  • a value only Bind understands now binds;
  • a Bind that transforms its input now takes effect.

Types without a Bind method are unaffected. types.Date implements Binder, and accepts the same values as before.

Array properties of exploded form objects bind

An array property of an exploded form object repeats its name once per element, as a top-level exploded array does: GET /users?orderBy=foo&orderBy=bar. This could never bind into a struct with an OrderBy *[]string field. It was rejected as field 'orderBy' specified multiple times, and with the swallowed error above, an optional parameter was silently dropped instead. Slice fields and pointers to slices now bind one element per value (#​194, part of #​193). Commas are not delimiters here, which matches top-level exploded arrays. This was originally reported as oapi-codegen/oapi-codegen#476.

Self-parsing types bind in more places

BindStringToObject found a type's own parsing logic only in two narrow cases, so anything else without a built-in conversion failed with can not bind to destination of type: slice or struct. That included encoding.TextUnmarshaler types such as net.IP, netip.Addr and big.Int, a Binder slice, struct or map behind the pointer of an optional field, and an optional *uuid.UUID property of an exploded form object. Where no built-in conversion applies, the destination is now checked for Binder and then encoding.TextUnmarshaler before giving up (#​197, part of #​196).

This only runs where binding used to fail. Built-in conversions keep their precedence: time.Time and types.Date keep their lenient parsing, and format: byte still base64-decodes first.

Form bodies: dates and times, nullable properties, maps, and no more panics

BindForm and MarshalForm decided what a value is from its reflect.Kind alone, which dropped some properties without an error and panicked on others (#​204, closes #​202):

  • Dates and times. types.Date and time.Time were walked as objects with no fields, so a format: date or format: date-time property of a form body was neither sent by a generated client nor received by a generated strict server, with no error on either side. They are now single values, as is any type that parses or marshals itself as text. BindForm reads such a type from its plain key, and still accepts the bracketed keys it was written with before.
  • Nullable properties and maps. MarshalForm writes a nullable.Nullable as the value it holds, and a map as name[key]=value, which is what BindForm reads. Both used to come out in Go's map syntax, name=map[true:x]. A null property is not written, since a form can not express one.
  • Panics. A form key with an unclosed bracket, such as topic[, panicked BindForm for any array property or object with additional properties, which a client of a generated strict server could trigger. The key is now ignored. Also gone are the panics for a value sent for an any property (now an error), a file sent under an additional property, MarshalForm on an object with additional properties or an empty any, and a []byte in a styled form property or nested in a styled parameter. The last one also affected StyleParam, where it is now an error.
  • Cost. Each nested array, map or set of additional properties was found by scanning every key of the form, which made binding quadratic in the size of the request: a 1.4 MB body of 40,000 nested elements took 31.8 s to bind, and now takes 41 ms.
  • Errors are deterministic. Keys are visited in sorted order, so a form with several bad values reports the same one each time.

BindForm also reads back what MarshalForm writes for a property with an encoding. Arrays bind from repeated keys or one delimited value in the form, spaceDelimited and pipeDelimited styles, an application/json property decodes into its own field, and the older indexed keys are still accepted where a property has no plain key. Thanks to @​go165 (#​201). The generator side of form encodings is tracked in oapi-codegen/oapi-codegen#2676.

types.Email rejects addresses that do not round-trip

Email.UnmarshalJSON accepted an address with a quoted local part, such as "a b"@example.com, and stored it with the quoting removed, a b@example.com. MarshalJSON then refused to write that value. Such an address is now rejected when it is read, with email: failed to pass regex validation, so anything UnmarshalJSON accepts can be marshaled and parses back to the same value. These are valid RFC 5322 addresses, and input that carries one will now fail where it used to succeed. Thanks to @​aibeshkov, who found this by fuzzing the type (#​200).

Clearer error for nested arrays in styled parameters

Styling an object that has an array property failed with a bare unsupported type []T. OpenAPI defines style-based serialization only for primitives, arrays of primitives and flat objects, so there is no wire format for it. The error now says so, and suggests declaring the parameter with content: application/json or style: deepObject (#​192, closes #​191). Nothing that serialized before has changed.

☢️ Breaking changes

🚀 New features and improvements

🐛 Bug fixes

📝 Documentation updates

📦 Dependency updates

Sponsors

We would like to thank our sponsors for their support during this release.

DevZero logo

Cybozu logo

New contributors


Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants