bump(go-openapi/validate): d509235108fcf6ab4913d2dcb3a2260c0db2108e

This commit is contained in:
Nikhita Raghunath
2017-11-22 16:34:36 +05:30
parent 2b530438f1
commit 66a4e5122a
17 changed files with 301 additions and 116 deletions

View File

@@ -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()
}
}