Skip to content

Commit

Permalink
openapi3filter: drop useless DefaultOptions (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Apr 18, 2023
1 parent d12c756 commit 994d4f0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/docs/openapi3filter.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions openapi3filter/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions openapi3filter/validate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion openapi3filter/validate_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 994d4f0

Please sign in to comment.