Repository navigation
chore(deps): update module github.com/oapi-codegen/runtime to v1.10.0 - #21
Open
renovate[bot] wants to merge 1 commit into
Open
renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
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.
This PR contains the following updates:
v1.9.1→v1.10.0Release Notes
oapi-codegen/runtime (github.com/oapi-codegen/runtime)
v1.10.0: : RFC 3986 query encoding, and more robust form and parameter bindingCompare 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 ago get.☢️ Breaking changes at a glance
%20, not+runtime.DefaultQueryEncoder = runtime.NetURLQueryEncoder{}MarshalFormwrites a self-marshaling type as its text,ip=192.0.2.1runtime.MarshalFormIgnoresTextMarshaler = trueBindFormrejects an indexed array with a gap, and ignores non-canonical indexesruntime.BindFormAllowsArrayGaps = true, at the cost of that protectionBinderis honored on an optional property of an exploded form objectBindertypesThe 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
%20DefaultQueryEncoderis nowRFC3986QueryEncoderwhere it wasNetURLQueryEncoder, so a generated client sends?q=a%20bwhere it sent?q=a+b(#190, closes #189). OpenAPI'sstyle: formfor query parameters is defined by RFC 6570, which encodes a space as%20.+belongs toapplication/x-www-form-urlencoded, which is the encoding of form bodies. A server that reads+as a space reads%20as 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.
deepObjectparameters go through the same encoder. Path parameters and form bodies are unchanged.To restore the previous encoding:
☢️ Breaking:
MarshalFormwrites self-marshaling types as textA type that implements
encoding.TextMarshaleris now a single value in a form body, whatever Go type it is made of. Anet.IPused to be written as its bytes,ip[0]=192&ip[1]=0&ip[2]=2&ip[3]=1, and is nowip=192.0.2.1(#204).BindFormin this release reads both layouts, butBindFormin 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: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:
BindFormarray indexes must run from zero without a gapBindFormsized an array by the highest index a form named, so the 20-byte bodytopic[4000000]=aallocated four million elements. Indexes now have to run from0without a gap, which keeps an indexed array no longer than the number of keys sent for it (#204).topic[0]=a&topic[2]=cused 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.topic[01]andtopic[-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,
BindFormAllowsArrayGapsaccepts them again and leaves the elements a form does not name at their zero value (#205). Non-canonical indexes are ignored either way.☢️ 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):?cursor=xyz&limit=abcreached the handler with no filter at all;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=abcfor 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:
Binderis honored on optional propertiesA type that implements
runtime.Binderdid not haveBindcalled 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 whoseBindaccepts50%and rejects anything over 100,150was accepted as an optional property and rejected everywhere else.Bindis now called in both cases. For such a property:Bindrejects, but the built-in parser accepted, is now an error;Bindunderstands now binds;Bindthat transforms its input now takes effect.Types without a
Bindmethod are unaffected.types.DateimplementsBinder, 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 anOrderBy *[]stringfield. It was rejected asfield '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
BindStringToObjectfound a type's own parsing logic only in two narrow cases, so anything else without a built-in conversion failed withcan not bind to destination of type: sliceorstruct. That includedencoding.TextUnmarshalertypes such asnet.IP,netip.Addrandbig.Int, aBinderslice, struct or map behind the pointer of an optional field, and an optional*uuid.UUIDproperty of an exploded form object. Where no built-in conversion applies, the destination is now checked forBinderand thenencoding.TextUnmarshalerbefore giving up (#197, part of #196).This only runs where binding used to fail. Built-in conversions keep their precedence:
time.Timeandtypes.Datekeep their lenient parsing, andformat: bytestill base64-decodes first.Form bodies: dates and times, nullable properties, maps, and no more panics
BindFormandMarshalFormdecided what a value is from itsreflect.Kindalone, which dropped some properties without an error and panicked on others (#204, closes #202):types.Dateandtime.Timewere walked as objects with no fields, so aformat: dateorformat: date-timeproperty 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.BindFormreads such a type from its plain key, and still accepts the bracketed keys it was written with before.MarshalFormwrites anullable.Nullableas the value it holds, and a map asname[key]=value, which is whatBindFormreads. 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.topic[, panickedBindFormfor 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 ananyproperty (now an error), a file sent under an additional property,MarshalFormon an object with additional properties or an emptyany, and a[]bytein a styled form property or nested in a styled parameter. The last one also affectedStyleParam, where it is now an error.BindFormalso reads back whatMarshalFormwrites for a property with an encoding. Arrays bind from repeated keys or one delimited value in theform,spaceDelimitedandpipeDelimitedstyles, anapplication/jsonproperty 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.Emailrejects addresses that do not round-tripEmail.UnmarshalJSONaccepted an address with a quoted local part, such as"a b"@example.com, and stored it with the quoting removed,a b@example.com.MarshalJSONthen refused to write that value. Such an address is now rejected when it is read, withemail: failed to pass regex validation, so anythingUnmarshalJSONaccepts 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 withcontent: application/jsonorstyle: 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.
New contributors
Configuration
📅 Schedule: (UTC)
🚦 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.
This PR was generated by Mend Renovate. View the repository job log.