Skip to content

Commit 994d4f0

Browse files
authored
openapi3filter: drop useless DefaultOptions (#785)
1 parent d12c756 commit 994d4f0

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

.github/docs/openapi3filter.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const ErrCodeOK = 0 ...
2-
var DefaultOptions = &Options{}
32
var ErrAuthenticationServiceMissing = errors.New("missing AuthenticationFunc")
43
var ErrInvalidEmptyValue = errors.New("empty value is not allowed")
54
var ErrInvalidRequired = errors.New("value is required but missing")

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ For more fine-grained control over the error message, you can pass a custom `ope
255255

256256
```go
257257
func validationOptions() *openapi3filter.Options {
258-
options := openapi3filter.DefaultOptions
258+
options := &openapi3filter.Options{}
259259
options.WithCustomSchemaErrorFunc(safeErrorMessage)
260260
return options
261261
}
@@ -269,6 +269,9 @@ This will change the schema validation errors to return only the `Reason` field,
269269

270270
## Sub-v0 breaking API changes
271271

272+
### v0.116.0
273+
* Dropped `openapi3filter.DefaultOptions`. Use `&openapi3filter.Options{}` directly instead.
274+
272275
### v0.113.0
273276
* The string format `email` has been removed by default. To use it please call `openapi3.DefineStringFormat("email", openapi3.FormatOfStringForEmail)`.
274277
* Field `openapi3.T.Components` is now a pointer.

openapi3filter/options.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ package openapi3filter
22

33
import "github.com/getkin/kin-openapi/openapi3"
44

5-
// DefaultOptions do not set an AuthenticationFunc.
6-
// A spec with security schemes defined will not pass validation
7-
// unless an AuthenticationFunc is defined.
8-
var DefaultOptions = &Options{}
9-
105
// Options used by ValidateRequest and ValidateResponse
116
type Options struct {
127
// Set ExcludeRequestBody so ValidateRequest skips request body validation
@@ -27,6 +22,8 @@ type Options struct {
2722

2823
MultiError bool
2924

25+
// A document with security schemes defined will not pass validation
26+
// unless an AuthenticationFunc is defined.
3027
// See NoopAuthenticationFunc
3128
AuthenticationFunc AuthenticationFunc
3229

openapi3filter/validate_request.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ValidateRequest(ctx context.Context, input *RequestValidationInput) (err er
3434

3535
options := input.Options
3636
if options == nil {
37-
options = DefaultOptions
37+
options = &Options{}
3838
}
3939
route := input.Route
4040
operation := route.Operation
@@ -116,7 +116,7 @@ func ValidateParameter(ctx context.Context, input *RequestValidationInput, param
116116

117117
options := input.Options
118118
if options == nil {
119-
options = DefaultOptions
119+
options = &Options{}
120120
}
121121

122122
var value interface{}
@@ -202,7 +202,7 @@ func ValidateRequestBody(ctx context.Context, input *RequestValidationInput, req
202202

203203
options := input.Options
204204
if options == nil {
205-
options = DefaultOptions
205+
options = &Options{}
206206
}
207207

208208
if req.Body != http.NoBody && req.Body != nil {
@@ -358,7 +358,7 @@ func validateSecurityRequirement(ctx context.Context, input *RequestValidationIn
358358
// Get authentication function
359359
options := input.Options
360360
if options == nil {
361-
options = DefaultOptions
361+
options = &Options{}
362362
}
363363
f := options.AuthenticationFunc
364364
if f == nil {

openapi3filter/validate_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func ValidateResponse(ctx context.Context, input *ResponseValidationInput) error
3939
route := input.RequestValidationInput.Route
4040
options := input.Options
4141
if options == nil {
42-
options = DefaultOptions
42+
options = &Options{}
4343
}
4444

4545
// Find input for the current status

0 commit comments

Comments
 (0)