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
Copy file name to clipboardExpand all lines: oapi_validate.go
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,9 @@ type Options struct {
103
103
SilenceServersWarningbool
104
104
// DoNotValidateServers ensures that there is no Host validation performed (see `SilenceServersWarning` and https://github.com/deepmap/oapi-codegen/issues/882 for more details)
105
105
DoNotValidateServersbool
106
+
// Prefix allows (optionally) trimming a prefix from the API path.
107
+
// This may be useful if your API is routed to an internal path that is different from the OpenAPI specification.
108
+
Prefixstring
106
109
}
107
110
108
111
// OapiRequestValidator Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, with a default set of configuration.
@@ -159,6 +162,11 @@ func performRequestValidationForErrorHandler(next http.Handler, w http.ResponseW
159
162
// Note that this is an inline-and-modified version of `validateRequest`, with a simplified control flow and providing full access to the `error` for the `ErrorHandlerWithOpts` function.
160
163
funcperformRequestValidationForErrorHandlerWithOpts(next http.Handler, w http.ResponseWriter, r*http.Request, router routers.Router, options*Options) {
Copy file name to clipboardExpand all lines: oapi_validate_example_test.go
+119Lines changed: 119 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -843,3 +843,122 @@ paths:
843
843
// Received an HTTP 400 response. Expected HTTP 400
844
844
// Response body: There was a bad request
845
845
}
846
+
847
+
// In the case that your public OpenAPI spec documents an API which does /not/ match your internal API endpoint setup, you may want to set the `Prefix` option to allow rewriting paths
// 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