diff --git a/.github/docs/openapi3filter.txt b/.github/docs/openapi3filter.txt index 2dbca0444..fadf3b315 100644 --- a/.github/docs/openapi3filter.txt +++ b/.github/docs/openapi3filter.txt @@ -1,5 +1,4 @@ const ErrCodeOK = 0 ... -var DefaultOptions = &Options{} var ErrAuthenticationServiceMissing = errors.New("missing AuthenticationFunc") var ErrInvalidEmptyValue = errors.New("empty value is not allowed") var ErrInvalidRequired = errors.New("value is required but missing") diff --git a/README.md b/README.md index b85af9864..500f07a5c 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,7 @@ For more fine-grained control over the error message, you can pass a custom `ope ```go func validationOptions() *openapi3filter.Options { - options := openapi3filter.DefaultOptions + options := &openapi3filter.Options{} options.WithCustomSchemaErrorFunc(safeErrorMessage) return options } @@ -269,6 +269,9 @@ This will change the schema validation errors to return only the `Reason` field, ## Sub-v0 breaking API changes +### v0.116.0 +* Dropped `openapi3filter.DefaultOptions`. Use `&openapi3filter.Options{}` directly instead. + ### v0.113.0 * The string format `email` has been removed by default. To use it please call `openapi3.DefineStringFormat("email", openapi3.FormatOfStringForEmail)`. * Field `openapi3.T.Components` is now a pointer. diff --git a/openapi3filter/options.go b/openapi3filter/options.go index 4ea9e9907..4bda60a26 100644 --- a/openapi3filter/options.go +++ b/openapi3filter/options.go @@ -2,11 +2,6 @@ package openapi3filter import "github.com/getkin/kin-openapi/openapi3" -// DefaultOptions do not set an AuthenticationFunc. -// A spec with security schemes defined will not pass validation -// unless an AuthenticationFunc is defined. -var DefaultOptions = &Options{} - // Options used by ValidateRequest and ValidateResponse type Options struct { // Set ExcludeRequestBody so ValidateRequest skips request body validation @@ -27,6 +22,8 @@ type Options struct { MultiError bool + // A document with security schemes defined will not pass validation + // unless an AuthenticationFunc is defined. // See NoopAuthenticationFunc AuthenticationFunc AuthenticationFunc diff --git a/openapi3filter/validate_request.go b/openapi3filter/validate_request.go index a8106a7c8..f4debcda1 100644 --- a/openapi3filter/validate_request.go +++ b/openapi3filter/validate_request.go @@ -34,7 +34,7 @@ func ValidateRequest(ctx context.Context, input *RequestValidationInput) (err er options := input.Options if options == nil { - options = DefaultOptions + options = &Options{} } route := input.Route operation := route.Operation @@ -116,7 +116,7 @@ func ValidateParameter(ctx context.Context, input *RequestValidationInput, param options := input.Options if options == nil { - options = DefaultOptions + options = &Options{} } var value interface{} @@ -202,7 +202,7 @@ func ValidateRequestBody(ctx context.Context, input *RequestValidationInput, req options := input.Options if options == nil { - options = DefaultOptions + options = &Options{} } if req.Body != http.NoBody && req.Body != nil { @@ -358,7 +358,7 @@ func validateSecurityRequirement(ctx context.Context, input *RequestValidationIn // Get authentication function options := input.Options if options == nil { - options = DefaultOptions + options = &Options{} } f := options.AuthenticationFunc if f == nil { diff --git a/openapi3filter/validate_response.go b/openapi3filter/validate_response.go index 08ea4e19d..dca13380a 100644 --- a/openapi3filter/validate_response.go +++ b/openapi3filter/validate_response.go @@ -39,7 +39,7 @@ func ValidateResponse(ctx context.Context, input *ResponseValidationInput) error route := input.RequestValidationInput.Route options := input.Options if options == nil { - options = DefaultOptions + options = &Options{} } // Find input for the current status