Skip to content

Commit 4dbd1fe

Browse files
committed
docs: improve comments for exported types
1 parent 5559558 commit 4dbd1fe

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

oapi_validate.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,33 @@ import (
2323
// ErrorHandler is called when there is an error in validation
2424
type ErrorHandler func(w http.ResponseWriter, message string, statusCode int)
2525

26-
// MultiErrorHandler is called when oapi returns a MultiError type
26+
// MultiErrorHandler is called when the OpenAPI filter returns an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError)
2727
type MultiErrorHandler func(openapi3.MultiError) (int, error)
2828

29-
// Options to customize request validation, openapi3filter specified options will be passed through.
29+
// Options allows configuring the OapiRequestValidator.
3030
type Options struct {
31-
Options openapi3filter.Options
32-
ErrorHandler ErrorHandler
31+
// Options contains any configuration for the underlying `openapi3filter`
32+
Options openapi3filter.Options
33+
// ErrorHandler is called when a validation error occurs.
34+
//
35+
// If not provided, `http.Error` will be called
36+
ErrorHandler ErrorHandler
37+
// MultiErrorHandler is called when there is an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError) returned by the `openapi3filter`.
38+
//
39+
// If not provided `defaultMultiErrorHandler` will be used.
3340
MultiErrorHandler MultiErrorHandler
3441
// SilenceServersWarning allows silencing a warning for https://github.com/deepmap/oapi-codegen/issues/882 that reports when an OpenAPI spec has `spec.Servers != nil`
3542
SilenceServersWarning bool
3643
}
3744

38-
// OapiRequestValidator Creates middleware to validate request by OpenAPI spec.
45+
// OapiRequestValidator Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, with a default set of configuration.
3946
func OapiRequestValidator(spec *openapi3.T) func(next http.Handler) http.Handler {
4047
return OapiRequestValidatorWithOptions(spec, nil)
4148
}
4249

43-
// OapiRequestValidatorWithOptions Creates middleware to validate request by OpenAPI spec.
50+
// OapiRequestValidatorWithOptions Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, allowing explicit configuration.
51+
//
52+
// NOTE that this may panic if the OpenAPI spec isn't valid, or if it cannot be used to create the middleware
4453
func OapiRequestValidatorWithOptions(spec *openapi3.T, options *Options) func(next http.Handler) http.Handler {
4554
if spec.Servers != nil && (options == nil || !options.SilenceServersWarning) {
4655
log.Println("WARN: OapiRequestValidatorWithOptions called with an OpenAPI spec that has `Servers` set. This may lead to an HTTP 400 with `no matching operation was found` when sending a valid request, as the validator performs `Host` header validation. If you're expecting `Host` header validation, you can silence this warning by setting `Options.SilenceServersWarning = true`. See https://github.com/deepmap/oapi-codegen/issues/882 for more information.")

0 commit comments

Comments
 (0)