Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ on:
jobs:
test:
uses: go-openapi/ci-workflows/.github/workflows/go-test.yml@befbc52f24215555cb601b0d824b2987c1d49d0b # v0.4.3
with:
extra-flags: '-tags poolsdebug'
secrets: inherit
20 changes: 10 additions & 10 deletions default_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type defaultValidator struct {

// Validate validates the default values declared in the swagger spec.
func (d *defaultValidator) Validate() *Result {
errs := pools.poolOfResults.BorrowResult() // will redeem when merged
errs := validatorPools.results.Borrow() // will redeem when merged

if d == nil || d.SpecValidator == nil {
return errs
Expand Down Expand Up @@ -73,7 +73,7 @@ func (d *defaultValidator) validateDefaultValueValidAgainstSchema() *Result {
// every default value that is specified must validate against the schema for that property
// headers, items, parameters, schema

res := pools.poolOfResults.BorrowResult() // will redeem when merged
res := validatorPools.results.Borrow() // will redeem when merged
s := d.SpecValidator

for method, pathItem := range s.expandedAnalyzer().Operations() {
Expand All @@ -96,7 +96,7 @@ func (d *defaultValidator) validateDefaultValueValidAgainstSchema() *Result {
res.addErrorsAt(s.parameterPath(path, method, param.In, param.Name), defaultValueDoesNotValidateMsg(param.Name, param.In))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -107,7 +107,7 @@ func (d *defaultValidator) validateDefaultValueValidAgainstSchema() *Result {
res.addErrorsAt(s.parameterPath(path, method, param.In, param.Name), defaultValueItemsDoesNotValidateMsg(param.Name, param.In))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -118,7 +118,7 @@ func (d *defaultValidator) validateDefaultValueValidAgainstSchema() *Result {
res.addErrorsAt(s.parameterPath(path, method, param.In, param.Name), defaultValueDoesNotValidateMsg(param.Name, param.In))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (d *defaultValidator) validateDefaultInResponse(
res.addErrorsAt(responseHeaderPath(path, method, responseCodeAsStr, nm), defaultValueHeaderDoesNotValidateMsg(operationID, nm, responseName))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -184,7 +184,7 @@ func (d *defaultValidator) validateDefaultInResponse(
res.addErrorsAt(responseHeaderPath(path, method, responseCodeAsStr, nm), defaultValueHeaderItemsDoesNotValidateMsg(operationID, nm, responseName))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -206,7 +206,7 @@ func (d *defaultValidator) validateDefaultInResponse(
res.addErrorsAt(responsePath(path, method, responseCodeAsStr), defaultValueInDoesNotValidateMsg(operationID, responseName))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}
return res
Expand All @@ -218,7 +218,7 @@ func (d *defaultValidator) validateDefaultValueSchemaAgainstSchema(path pathSegm
return nil
}
d.beingVisited(path)
res := pools.poolOfResults.BorrowResult()
res := validatorPools.results.Borrow()
s := d.SpecValidator

if schema.Default != nil {
Expand Down Expand Up @@ -264,7 +264,7 @@ func (d *defaultValidator) validateDefaultValueSchemaAgainstSchema(path pathSegm
// NOTE: Temporary duplicated code. Need to refactor with examples

func (d *defaultValidator) validateDefaultValueItemsAgainstSchema(path pathSegments, in string, root any, items *spec.Items) *Result {
res := pools.poolOfResults.BorrowResult()
res := validatorPools.results.Borrow()
s := d.SpecValidator
if items != nil {
if items.Default != nil {
Expand Down
20 changes: 10 additions & 10 deletions example_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type exampleValidator struct {
// - individual property
// - responses
func (ex *exampleValidator) Validate() *Result {
errs := pools.poolOfResults.BorrowResult()
errs := validatorPools.results.Borrow()

if ex == nil || ex.SpecValidator == nil {
return errs
Expand Down Expand Up @@ -63,7 +63,7 @@ func (ex *exampleValidator) validateExampleValueValidAgainstSchema() *Result {
// in: schemas, properties, object, items
// not in: headers, parameters without schema

res := pools.poolOfResults.BorrowResult()
res := validatorPools.results.Borrow()
s := ex.SpecValidator

for method, pathItem := range s.expandedAnalyzer().Operations() {
Expand All @@ -86,7 +86,7 @@ func (ex *exampleValidator) validateExampleValueValidAgainstSchema() *Result {
res.addWarningsAt(s.parameterPath(path, method, param.In, param.Name), exampleValueDoesNotValidateMsg(param.Name, param.In))
res.MergeAsWarnings(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -97,7 +97,7 @@ func (ex *exampleValidator) validateExampleValueValidAgainstSchema() *Result {
res.addWarningsAt(s.parameterPath(path, method, param.In, param.Name), exampleValueItemsDoesNotValidateMsg(param.Name, param.In))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -108,7 +108,7 @@ func (ex *exampleValidator) validateExampleValueValidAgainstSchema() *Result {
res.addWarningsAt(s.parameterPath(path, method, param.In, param.Name), exampleValueDoesNotValidateMsg(param.Name, param.In))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (ex *exampleValidator) validateExampleInResponse(
res.addWarningsAt(responseHeaderPath(path, method, responseCodeAsStr, nm), exampleValueHeaderDoesNotValidateMsg(operationID, nm, responseName))
res.MergeAsWarnings(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -174,7 +174,7 @@ func (ex *exampleValidator) validateExampleInResponse(
res.addWarningsAt(responseHeaderPath(path, method, responseCodeAsStr, nm), exampleValueHeaderItemsDoesNotValidateMsg(operationID, nm, responseName))
res.MergeAsWarnings(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand All @@ -196,7 +196,7 @@ func (ex *exampleValidator) validateExampleInResponse(
res.addWarningsAt(responsePath(path, method, responseCodeAsStr), exampleValueInDoesNotValidateMsg(operationID, responseName))
res.Merge(red)
} else if red.wantsRedeemOnMerge {
pools.poolOfResults.RedeemResult(red)
redeemResult(red)
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func (ex *exampleValidator) validateExampleValueSchemaAgainstSchema(path pathSeg
}
ex.beingVisited(path)
s := ex.SpecValidator
res := pools.poolOfResults.BorrowResult()
res := validatorPools.results.Borrow()

if schema.Example != nil {
res.MergeAsWarnings(
Expand Down Expand Up @@ -274,7 +274,7 @@ func (ex *exampleValidator) validateExampleValueSchemaAgainstSchema(path pathSeg
//

func (ex *exampleValidator) validateExampleValueItemsAgainstSchema(path pathSegments, in string, root any, items *spec.Items) *Result {
res := pools.poolOfResults.BorrowResult()
res := validatorPools.results.Borrow()
s := ex.SpecValidator
if items != nil {
if items.Example != nil {
Expand Down
6 changes: 3 additions & 3 deletions formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newFormatValidator(path pathSegments, in, format string, formats strfmt.Reg

var f *formatValidator
if opts.recycleValidators {
f = pools.poolOfFormatValidators.BorrowValidator()
f = validatorPools.formatValidators.Borrow()
} else {
f = new(formatValidator)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func (f *formatValidator) Validate(val any) *Result {

var result *Result
if f.Options.recycleResult {
result = pools.poolOfResults.BorrowResult()
result = validatorPools.results.Borrow()
} else {
result = new(Result)
}
Expand All @@ -89,5 +89,5 @@ func (f *formatValidator) setPath(path pathSegments) {
}

func (f *formatValidator) redeem() {
pools.poolOfFormatValidators.RedeemValidator(f)
validatorPools.formatValidators.Redeem(f)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/go-openapi/swag/fileutils v0.28.0
github.com/go-openapi/swag/jsonutils v0.28.0
github.com/go-openapi/swag/loading v0.28.0
github.com/go-openapi/swag/pools v0.28.0
github.com/go-openapi/swag/stringutils v0.28.0
github.com/go-openapi/testify/v2 v2.6.0
go.yaml.in/yaml/v3 v3.0.5
Expand All @@ -19,7 +20,6 @@ require (
require (
github.com/go-openapi/jsonreference v1.0.0 // indirect
github.com/go-openapi/swag/mangling v0.28.0 // indirect
github.com/go-openapi/swag/pools v0.28.0 // indirect
github.com/go-openapi/swag/typeutils v0.28.0 // indirect
github.com/go-openapi/swag/yamlutils v0.28.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (h *errorHelper) sErr(err errors.Error, recycle bool) *Result {
func (h *errorHelper) sErrAt(at pathSegments, err errors.Error, recycle bool) *Result {
var result *Result
if recycle {
result = pools.poolOfResults.BorrowResult()
result = validatorPools.results.Borrow()
} else {
result = new(Result)
}
Expand Down
14 changes: 7 additions & 7 deletions object_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newObjectValidator(path pathSegments, in string,

var v *objectValidator
if opts.recycleValidators {
v = pools.poolOfObjectValidators.BorrowValidator()
v = validatorPools.objectValidators.Borrow()
} else {
v = new(objectValidator)
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func (o *objectValidator) Validate(data any) *Result {

var res *Result
if o.Options.recycleResult {
res = pools.poolOfResults.BorrowResult()
res = validatorPools.results.Borrow()
} else {
res = new(Result)
}
Expand Down Expand Up @@ -328,9 +328,9 @@ func (o *objectValidator) validatePropertiesSchema(val map[string]any, res *Resu

// Property types:
// - regular Property
pSchema := pools.poolOfSchemas.BorrowSchema() // recycle a spec.Schema object which lifespan extends only to the validation of properties
pSchema := validatorPools.schemas.Borrow() // recycle a spec.Schema object which lifespan extends only to the validation of properties
defer func() {
pools.poolOfSchemas.RedeemSchema(pSchema)
validatorPools.schemas.Redeem(pSchema)
}()

for pName := range o.Properties {
Expand Down Expand Up @@ -387,9 +387,9 @@ func (o *objectValidator) validatePatternProperty(key string, value any, result
succeededOnce := false
patterns := make([]string, 0, len(o.PatternProperties))

schema := pools.poolOfSchemas.BorrowSchema()
schema := validatorPools.schemas.Borrow()
defer func() {
pools.poolOfSchemas.RedeemSchema(schema)
validatorPools.schemas.Redeem(schema)
}()

for k := range o.PatternProperties {
Expand Down Expand Up @@ -420,5 +420,5 @@ func (o *objectValidator) setPath(path pathSegments) {
}

func (o *objectValidator) redeem() {
pools.poolOfObjectValidators.RedeemValidator(o)
validatorPools.objectValidators.Redeem(o)
}
Loading
Loading