Repository navigation
Releases
v1.3.1: keep the validated request body value by default
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
- Keep the validated request body value by default (#91) @mromaszewicz
📦 Dependency updates
- Bump kin-openapi to v0.152.0 in the internal test modules (#92) @mromaszewicz
Sponsors
We would like to thank our sponsors for their support during this release.
New contributors
- No new contributors
v1.3.0: kin-openapi v0.152.0 dependency update
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
$refare ignored, as the specification requires. - Integer parameters are parsed as base 10 only.
spaceDelimitedandpipeDelimitedquery parameters default toexplode: false.openapi3filter.Options.KeepValidatedValueis available for passing throughOptions.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.
New contributors
- No new contributors
OpenAPI 3.1, Go 1.25
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
- feat: Add path Prefix option to validate (#54) @Fedott, @claude, @GreyXor, Jamie Tanna, @mromaszewicz
🐛 Bug fixes
- Add query string to validation (#21) @marcwickenden
- fix: don't clone request in prefix stripping (#70) @mromaszewicz, @claude
- feat: add ability to skip validation checks (#66) @jamietanna, @claude, @mromaszewicz
👻 Maintenance
- chore: Update Go to 1.24 and update dependencies (#72) @mromaszewicz, @claude
- Fix release drafter configuration (#71) @mromaszewicz
✍ Other changes
- chore: add
tidy-ciMake task (#77) @jamietanna - build: use a re-usable, single, workflow for running CI (#64) @jamietanna
📦 Dependency updates
8 changes
- chore(deps): update release-drafter/release-drafter action to v7.6.0 (#74) @renovate[bot]
- Update several dependencies (#83) @mromaszewicz
- Update Go to 1.25 and kin (#79) @GreyXor, @mromaszewicz
- chore(deps): update oapi-codegen/actions action to v0.8.0 (#78) @renovate[bot]
- chore(deps): update release-drafter/release-drafter action to v7.2.0 (#73) @renovate[bot], @mromaszewicz
- chore(deps): update release-drafter/release-drafter action to v7 (#68) @renovate[bot], @mromaszewicz
- chore(deps): update oapi-codegen/actions action to v0.4.0 (#65) @renovate[bot]
- chore(deps): update module github.com/golangci/golangci-lint to v2.1.6 (#48) @renovate[bot]
Sponsors
We would like to thank our sponsors for their support during this release.
v1.1.2: Request bodies can now be re-used, after being read in an `AuthenticationFunc` and Go 1.22+-only
🔊 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
- build: build against Go 1.23 and 1.24 (#45) @jamietanna
📦 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.
v1.1.1: fix an incorrect HTTP status code (in an unlikely failure case)
🐛 Bug fixes
- fix: correct error code (#44) @jamietanna
📦 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.
v1.1.0: Better error handling, allow not validating `Servers` (by configuration) and return an HTTP 405 Method Not Allowed where appropriate
🔊 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
- feat: add error handler with more configuration (#35) @jamietanna @pebo @mikeschinkel @MattiasMartens
- refactor: migrate
errorto a method parameter, not part ofErrorHandlerOpts(#43) @jamietanna
- refactor: migrate
- feat: allow not validating
Serversat all (#37) @jamietanna
🐛 Bug fixes
📝 Documentation updates
- docs: correct accidentally hardcoded error message (#36) @jamietanna
- docs: rewrite README, add example test + improve comments (#30) @jamietanna
- docs(sponsors): add
FUNDING.yml(#20) @jamietanna
👻 Maintenance
- chore(deps): remove
testutil(#33) @jamietanna - chore: remove references to Swagger (#32) @jamietanna
📦 Dependency updates
- chore(deps): update module github.com/golangci/golangci-lint to v2.1.4 (#38) @renovate[bot]
- chore(deps): update module github.com/golangci/golangci-lint to v2 (#28) @renovate[bot]
- chore(deps): pin dependencies (#31) @renovate[bot]
Sponsors
We would like to thank our sponsors for their support during this release.
v1.0.2
👻 Maintenance
- Simplify CI build matrix + build against Go 1.22 (#12) @jamietanna
- Migrate to separate
testutilpackage (#7) @jamietanna - Onboard to Release Drafter (#8) @jamietanna
📦 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