Skip to content

Releases: oapi-codegen/nethttp-middleware

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

30 Apr 16:33
Compare
Choose a tag to compare

πŸ”Š 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)

25 Apr 09:30
Compare
Choose a tag to compare

πŸ› 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

25 Apr 07:55
Compare
Choose a tag to compare

πŸ”Š 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

  • 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.

Elastic logo

DevZero logo

Speakeasy logo

Cybozu logo

Livepeer logo

v1.0.2

04 Jun 05:57
Compare
Choose a tag to compare

πŸ‘» 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

06 Nov 16:18
Compare
Choose a tag to compare

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