bump(go-openapi/validate): d509235108fcf6ab4913d2dcb3a2260c0db2108e
This commit is contained in:
30
vendor/github.com/go-openapi/validate/result.go
generated
vendored
30
vendor/github.com/go-openapi/validate/result.go
generated
vendored
@@ -14,12 +14,32 @@
|
||||
|
||||
package validate
|
||||
|
||||
import "github.com/go-openapi/errors"
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// Debug is true when the SWAGGER_DEBUG env var is not empty
|
||||
Debug = os.Getenv("SWAGGER_DEBUG") != ""
|
||||
)
|
||||
|
||||
type Defaulter interface {
|
||||
Apply()
|
||||
}
|
||||
|
||||
type DefaulterFunc func()
|
||||
|
||||
func (f DefaulterFunc) Apply() {
|
||||
f()
|
||||
}
|
||||
|
||||
// Result represents a validation result
|
||||
type Result struct {
|
||||
Errors []error
|
||||
MatchCount int
|
||||
Defaulters []Defaulter
|
||||
}
|
||||
|
||||
// Merge merges this result with the other one, preserving match counts etc
|
||||
@@ -29,11 +49,13 @@ func (r *Result) Merge(other *Result) *Result {
|
||||
}
|
||||
r.AddErrors(other.Errors...)
|
||||
r.MatchCount += other.MatchCount
|
||||
r.Defaulters = append(r.Defaulters, other.Defaulters...)
|
||||
return r
|
||||
}
|
||||
|
||||
// AddErrors adds errors to this validation result
|
||||
func (r *Result) AddErrors(errors ...error) {
|
||||
// TODO: filter already existing errors
|
||||
r.Errors = append(r.Errors, errors...)
|
||||
}
|
||||
|
||||
@@ -59,3 +81,9 @@ func (r *Result) AsError() error {
|
||||
}
|
||||
return errors.CompositeValidationError(r.Errors...)
|
||||
}
|
||||
|
||||
func (r *Result) ApplyDefaults() {
|
||||
for _, d := range r.Defaulters {
|
||||
d.Apply()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user