Skip to content

Commit cc3e60b

Browse files
committed
updated to latest API from validator
1 parent a547060 commit cc3e60b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

mock/mock_engine.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"sync"
1414

15+
"github.com/pb33f/libopenapi-validator/config"
1516
libopenapierrs "github.com/pb33f/libopenapi-validator/errors"
1617
"github.com/pb33f/libopenapi-validator/helpers"
1718
"github.com/pb33f/libopenapi-validator/paths"
@@ -26,7 +27,7 @@ type ResponseMockEngine struct {
2627
validator validation.HttpValidator
2728
mockEngine *renderer.MockGenerator
2829
pretty bool
29-
regexCache *sync.Map
30+
validationOpts *config.ValidationOptions
3031
hardValidation bool // when true, reject requests with validation errors
3132
}
3233

@@ -45,7 +46,7 @@ func NewMockEngine(document *v3.Document, pretty, useAllPropertyExamples bool) *
4546
validator: validation.NewHttpValidator(document),
4647
mockEngine: me,
4748
pretty: pretty,
48-
regexCache: &sync.Map{},
49+
validationOpts: config.NewValidationOptions(config.WithRegexCache(&sync.Map{})),
4950
hardValidation: true, // default to rejecting on validation errors for backward compatibility
5051
}
5152
}
@@ -67,7 +68,7 @@ func NewStrictMockEngine(document *v3.Document, pretty, useAllPropertyExamples b
6768
validator: validation.NewStrictHttpValidator(document),
6869
mockEngine: me,
6970
pretty: pretty,
70-
regexCache: &sync.Map{},
71+
validationOpts: config.NewValidationOptions(config.WithRegexCache(&sync.Map{})),
7172
hardValidation: true, // default to rejecting on validation errors for backward compatibility
7273
}
7374
}
@@ -218,7 +219,7 @@ func (rme *ResponseMockEngine) extractMediaTypeHeader(request *http.Request) str
218219
}
219220

220221
func (rme *ResponseMockEngine) findPath(request *http.Request) (*v3.PathItem, error) {
221-
path, errs, _ := paths.FindPath(request, rme.doc, rme.regexCache)
222+
path, errs, _ := paths.FindPath(request, rme.doc, rme.validationOpts)
222223
return path, rme.packErrors(errs)
223224
}
224225

mock/mock_engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ components:
518518
buf := bytes.NewBuffer([]byte(payload))
519519
request, _ := http.NewRequest(http.MethodPost, "https://api.pb33f.io/auth", buf)
520520
request.Header.Set(helpers.ContentTypeHeader, "application/json")
521-
request.Header.Set(helpers.AuthorizationHeader, "the science man")
521+
request.Header.Set(helpers.AuthorizationHeader, "Basic dGVzdFVzZXI6dGVzdFBhc3M=")
522522

523523
b, status, err := me.GenerateResponse(request)
524524
assert.NoError(t, err)

0 commit comments

Comments
 (0)