Skip to content

Commit 4588e4f

Browse files
committed
docs: improve comments for exported types
1 parent a0c8193 commit 4588e4f

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

oapi_validate.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,47 @@ func OapiValidatorFromYamlFile(path string) (echo.MiddlewareFunc, error) {
4646
return OapiRequestValidator(spec), nil
4747
}
4848

49-
// OapiRequestValidator creates a validator from an OpenAPI spec.
49+
// OapiRequestValidator Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, with a default set of configuration.
5050
func OapiRequestValidator(spec *openapi3.T) echo.MiddlewareFunc {
5151
return OapiRequestValidatorWithOptions(spec, nil)
5252
}
5353

5454
// ErrorHandler is called when there is an error in validation
5555
type ErrorHandler func(c echo.Context, err *echo.HTTPError) error
5656

57-
// MultiErrorHandler is called when oapi returns a MultiError type
57+
// MultiErrorHandler is called when the OpenAPI filter returns an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError)
5858
type MultiErrorHandler func(openapi3.MultiError) *echo.HTTPError
5959

6060
// Options to customize request validation. These are passed through to
6161
// openapi3filter.
6262
type Options struct {
63-
ErrorHandler ErrorHandler
64-
Options openapi3filter.Options
65-
ParamDecoder openapi3filter.ContentParameterDecoder
66-
UserData any
67-
Skipper echomiddleware.Skipper
63+
// ErrorHandler is called when a validation error occurs.
64+
//
65+
// If not provided, `http.Error` will be called
66+
ErrorHandler ErrorHandler
67+
// Options contains any configuration for the underlying `openapi3filter`
68+
Options openapi3filter.Options
69+
// ParamDecoder is the openapi3filter.ContentParameterDecoder to be used for the decoding of the request body
70+
//
71+
// If unset, a default will be used
72+
ParamDecoder openapi3filter.ContentParameterDecoder
73+
// UserData is any user-specified data to inject into the context.Context, which is then passed in to the validation function.
74+
//
75+
// Set on the Context with the key `UserDataKey`.
76+
UserData any
77+
// Skipper an echo Skipper to allow skipping the middleware.
78+
Skipper echomiddleware.Skipper
79+
// MultiErrorHandler is called when there is an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError) returned by the `openapi3filter`.
80+
//
81+
// If not provided `defaultMultiErrorHandler` will be used.
6882
MultiErrorHandler MultiErrorHandler
6983
// SilenceServersWarning allows silencing a warning for https://github.com/oapi-codegen/oapi-codegen/issues/882 that reports when an OpenAPI spec has `spec.Servers != nil`
7084
SilenceServersWarning bool
7185
}
7286

73-
// OapiRequestValidatorWithOptions creates a validator from an OpenAPI spec, with validation options
87+
// OapiRequestValidatorWithOptions Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, allowing explicit configuration.
88+
//
89+
// NOTE that this may panic if the OpenAPI spec isn't valid, or if it cannot be used to create the middleware
7490
func OapiRequestValidatorWithOptions(spec *openapi3.T, options *Options) echo.MiddlewareFunc {
7591
if spec.Servers != nil && (options == nil || !options.SilenceServersWarning) {
7692
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/oapi-codegen/oapi-codegen/issues/882 for more information.")

0 commit comments

Comments
 (0)