Skip to content

Commit dcc6504

Browse files
committed
comments
1 parent b12e798 commit dcc6504

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

oapi_validate.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,36 @@ import (
2626
// ErrorHandler is called when there is an error in validation
2727
type ErrorHandler func(w http.ResponseWriter, message string, statusCode int)
2828

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

32-
// Options to customize request validation, openapi3filter specified options will be passed through.
32+
// Options allows configuring the OapiRequestValidator.
3333
type Options struct {
34-
Options openapi3filter.Options
35-
ErrorHandler ErrorHandler
34+
// Options contains any filters for the underlying `openapi3filter`
35+
Options openapi3filter.Options
36+
// TODO
37+
// ErrorHandler is called when a validation error **??** TODO
38+
// If not provided, `http.Error` will be called
39+
ErrorHandler ErrorHandler
40+
// MultiErrorHandler is called when there is an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError) returned by the `openapi3filter`.
41+
// If not provided `defaultMultiErrorHandler` will be used.
42+
// TODO
43+
// TODO
3644
MultiErrorHandler MultiErrorHandler
3745
// SilenceServersWarning allows silencing a warning for https://github.com/deepmap/oapi-codegen/issues/882 that reports when an OpenAPI spec has `spec.Servers != nil`
3846
SilenceServersWarning bool
3947
}
4048

49+
// TODO
4150
// OapiRequestValidator Creates middleware to validate request by OpenAPI spec.
51+
// TODO
4252
func OapiRequestValidator(spec *openapi3.T) func(next http.Handler) http.Handler {
4353
return OapiRequestValidatorWithOptions(spec, nil)
4454
}
4555

56+
// TODO
4657
// OapiRequestValidatorWithOptions Creates middleware to validate request by OpenAPI spec.
58+
// TODO
4759
func OapiRequestValidatorWithOptions(spec *openapi3.T, options *Options) func(next http.Handler) http.Handler {
4860
if spec.Servers != nil && (options == nil || !options.SilenceServersWarning) {
4961
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)