Skip to content

Releases

v1.3.1: keep the validated request body value by default

Choose a tag to compare

@github-actions github-actions released this 23 Oct 06:23
f54b15f

This release enables openapi3filter.Options.KeepValidatedValue by default. It was meant to ship in v1.3.0 together with the kin-openapi v0.152.0 update, but was merged after that release was published.

With it on, the validator leaves the request body readable exactly as before and additionally keeps the decoded, validated JSON value on the body, reachable through its ValidatedValue() any method. Upcoming oapi-codegen strict server templates use this to bind the value that was actually validated instead of decoding the body a second time, which closes the gap described in oapi-codegen/oapi-codegen#2605 (encoding/json matches member names case-insensitively, so a second decode can pick up a member the validator never saw).

Handlers that read the body see no difference. The only costs are that the decoded value stays in memory for the lifetime of the request, and that the body no longer implements optional interfaces such as io.WriterTo.

To opt out, set DiscardValidatedValue: true in this middleware's Options. This setting overrides KeepValidatedValue in the embedded openapi3filter.Options. Middleware that replaces the request body must run before the validator, otherwise the validated value is lost.

🚀 New features and improvements

📦 Dependency updates

Sponsors

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

DevZero logo

Cybozu logo

New contributors

  • No new contributors

v1.3.0: kin-openapi v0.152.0 dependency update

Choose a tag to compare

@github-actions github-actions released this 23 Oct 04:02
cbcfbcf

This is a dependency update release. It moves the required kin-openapi version to v0.152.0, which also raises the minimum for every project using this middleware.

Behaviour changes that come with kin-openapi v0.150.0 to v0.152.0 and that users may notice:

  • JSON request bodies with duplicate member names are rejected when the binary is built with Go 1.27 and its default encoding/json (this is decided by the toolchain, not by this middleware).
  • In OpenAPI 3.0 documents, fields placed next to a $ref are ignored, as the specification requires.
  • Integer parameters are parsed as base 10 only.
  • spaceDelimited and pipeDelimited query parameters default to explode: false.
  • openapi3filter.Options.KeepValidatedValue is available for passing through Options.Options; it leaves the validated request body value on the request for handlers that can use it.

This release also picks up the kin-openapi security fix from v0.149.0 (GHSA-r277-6w6q-xmqw) for anyone still on an older version.

📦 Dependency updates

6 changes
  • fix(deps): update module github.com/getkin/kin-openapi to v0.152.0 (#90) @renovate[bot]
  • chore(deps): update oapi-codegen/actions action to v0.9.2 (#88) @renovate[bot]
  • chore(deps): update module github.com/golangci/golangci-lint to v2.15.0 (#87) @renovate[bot]
  • chore(deps): update release-drafter/release-drafter action to v7.10.0 (#86) @renovate[bot]
  • fix(deps): update module github.com/getkin/kin-openapi to v0.149.0 [security] (#85) @renovate[bot]
  • fix(deps): update module github.com/getkin/kin-openapi to v0.143.0 (#81) @renovate[bot]

Sponsors

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

DevZero logo

Cybozu logo

New contributors

  • No new contributors

OpenAPI 3.1, Go 1.25

Choose a tag to compare

@github-actions github-actions released this 19 Jul 17:21
9c6dabd

The major changes in this release are moving the Go requirement up to 1.25 so that we can pull in a version of kin-openapi which supports OpenAPI 3.1.

🚀 New features and improvements

🐛 Bug fixes

👻 Maintenance

✍ Other changes

📦 Dependency updates

8 changes

Sponsors

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

DevZero logo

Cybozu logo

v1.1.2: Request bodies can now be re-used, after being read in an `AuthenticationFunc` and Go 1.22+-only

Choose a tag to compare

@github-actions github-actions released this 30 Apr 16:33

🔊 Notable features

Go 1.22+ requirement

This module now requires Go 1.22 to build (previously we supported Go 1.20+).

Go 1.22 is still fairly old, and was marked as unsupported by the Go team in 2025-02-11, and is a new requirement as part of a dependency bump from kin-openapi.

This shouldn't technically be a breaking change given the age of the Go version used and it being unsupported - so ideally isn't being used heavily - but we wanted to flag it as such in case this came as a surprise.

Request body can now be re-used, after being read in an AuthenticationFunc

A longstanding issue with the openapi3filter from kin-openapi, that we build on top of for this middleware, resulted in cases where the request body could not be re-parsed after being consumed in a middleware's AuthenticationFunc.

This could lead to errors such as:

request body has an error: value is required but missing

Or:

request body has an error: reading failed: http: invalid Read on closed Body

This has now been fixed upstream, and therefore fixed for users of this middleware as part of this release.

👻 Maintenance

📦 Dependency updates

  • fix(deps)!: update module github.com/getkin/kin-openapi to v0.132.0 (#19) @renovate[bot]

Sponsors

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

Elastic logo

DevZero logo

Speakeasy logo

Cybozu logo

Livepeer logo

v1.1.1: fix an incorrect HTTP status code (in an unlikely failure case)

Choose a tag to compare

@github-actions github-actions released this 25 Apr 09:30

🐛 Bug fixes

📦 Dependency updates

  • chore(deps): update module github.com/golangci/golangci-lint to v2.1.5 (#39) @renovate[bot]

Sponsors

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

Elastic logo

DevZero logo

Speakeasy logo

Cybozu logo

Livepeer logo

v1.1.0: Better error handling, allow not validating `Servers` (by configuration) and return an HTTP 405 Method Not Allowed where appropriate

Choose a tag to compare

@github-actions github-actions released this 25 Apr 07:55

🔊 Notable features

Error handling is now significantly better

As part of #35, we have introduced a much more powerful means to handle the errors returned by the OpenAPI Validation middleware.

This has been a long-standing issue, and we appreciate the community's patience as well as different proposals over time.

Previously, when creating an error handler, the method signature was fairly lacking:

// create middleware
mw := middleware.OapiRequestValidatorWithOptions(spec, &middleware.Options{
    Options: openapi3filter.Options{
        AuthenticationFunc: authenticationFunc,
    },
    ErrorHandler: func(w http.ResponseWriter, message string, statusCode int) {
        http.Error(w, "This text/plain response will be returned to the caller: " + message, statusCode)
    },
})

This didn't give much information around what had happened - or in which route/endpoint - and not having the raw error made observability and additional steps to respond appropriately more difficult.

With this release, it's now possible to have the raw error, information about the current request + its context.Context, as well as some additional pieces of metadata inside the ErrorHandlerWithOpts:

// create middleware
mw := middleware.OapiRequestValidatorWithOptions(spec, &middleware.Options{
    // other options
    // ...
    ErrorHandlerWithOpts: func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request, opts middleware.ErrorHandlerOpts) {
        // NOTE that ErrorHandlerOpts contains further information, and allows us to add additional information in the future, in an extensible and non-breaking way
    }
})

There is a full example of usage in the Go doc for this project.

Note that the old method, ErrorHandler has been marked as deprecated - there is no planned removal date, and this is largely as a way to "nudge" folks to using the new, more powerful, method.

🚀 New features and improvements

🐛 Bug fixes

  • fix: return HTTP 405 when request method mismatch (#25) @nek023

📝 Documentation updates

👻 Maintenance

📦 Dependency updates

Sponsors

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

Elastic logo

DevZero logo

Speakeasy logo

Cybozu logo

Livepeer logo

v1.0.2

Choose a tag to compare

@github-actions github-actions released this 04 Jun 05:57

👻 Maintenance

📦 Dependency updates

  • fix(deps): update module github.com/getkin/kin-openapi to v0.124.0 (#2) @renovate
  • chore(deps): update release-drafter/release-drafter action to v6 (#10) @renovate
  • chore(deps): update actions/setup-go action to v5 (#9) @renovate
  • chore(deps): update actions/checkout action to v4 (#6) @renovate
  • chore(deps): update module github.com/golangci/golangci-lint to v1.59.0 (#1) @renovate

v1.0.1

Choose a tag to compare

@jamietanna jamietanna released this 06 Nov 16:18

Full Changelog: v1.0.0...v1.0.1