You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As noted in #63, an equivalent to Echo's `Skipper` would allow for
middleware users to opt-out of validation in a more straightforward way.
In a slightly different implementation to our `echo-middleware`, this
does not allow the `Skipper` to consume the body of the original
request, and instead duplicates it for the `Skipper`, and the other uses
of it.
Copy file name to clipboardExpand all lines: oapi_validate.go
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,11 @@
8
8
package nethttpmiddleware
9
9
10
10
import (
11
+
"bytes"
11
12
"context"
12
13
"errors"
13
14
"fmt"
15
+
"io"
14
16
"log"
15
17
"net/http"
16
18
"strings"
@@ -74,6 +76,11 @@ type ErrorHandlerOptsMatchedRoute struct {
74
76
// MultiErrorHandler is called when the OpenAPI filter returns an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError)
// Skipper is a function that runs before any validation middleware, and determines whether the given request should skip any validation middleware
80
+
//
81
+
// Return `true` if the request should be skipped
82
+
typeSkipperfunc(r*http.Request) bool
83
+
77
84
// Options allows configuring the OapiRequestValidator.
78
85
typeOptionsstruct {
79
86
// Options contains any configuration for the underlying `openapi3filter`
@@ -100,6 +107,9 @@ type Options struct {
100
107
SilenceServersWarningbool
101
108
// DoNotValidateServers ensures that there is no Host validation performed (see `SilenceServersWarning` and https://github.com/deepmap/oapi-codegen/issues/882 for more details)
102
109
DoNotValidateServersbool
110
+
111
+
// Skipper allows writing a function that runs before any middleware and determines whether the given request should skip any validation middleware
112
+
SkipperSkipper
103
113
}
104
114
105
115
// OapiRequestValidator Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, with a default set of configuration.
// NOTE that we need to make sure that the `Servers` aren't set, otherwise the OpenAPI validation middleware will validate that the `Host` header (of incoming requests) are targeting known `Servers` in the OpenAPI spec
0 commit comments