mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
update vendor/ dir to latest w/o heroku, moby
had to lock a lot of things in place
This commit is contained in:
53
vendor/github.com/go-openapi/validate/defaulter_test.go
generated
vendored
Normal file
53
vendor/github.com/go-openapi/validate/defaulter_test.go
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
package validate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
var defaulterFixturesPath = filepath.Join("fixtures", "defaulting")
|
||||
|
||||
func TestDefaulter(t *testing.T) {
|
||||
fname := filepath.Join(defaulterFixturesPath, "schema.json")
|
||||
b, err := ioutil.ReadFile(fname)
|
||||
assert.NoError(t, err)
|
||||
var schema spec.Schema
|
||||
assert.NoError(t, json.Unmarshal(b, &schema))
|
||||
|
||||
err = spec.ExpandSchema(&schema, nil, nil /*new(noopResCache)*/)
|
||||
assert.NoError(t, err, fname+" should expand cleanly")
|
||||
|
||||
validator := NewSchemaValidator(&schema, nil, "", strfmt.Default)
|
||||
x := map[string]interface{}{
|
||||
"nested": map[string]interface{}{},
|
||||
"all": map[string]interface{}{},
|
||||
"any": map[string]interface{}{},
|
||||
"one": map[string]interface{}{},
|
||||
}
|
||||
t.Logf("Before: %v", x)
|
||||
r := validator.Validate(x)
|
||||
assert.False(t, r.HasErrors(), fmt.Sprintf("unexpected validation error: %v", r.AsError()))
|
||||
|
||||
r.ApplyDefaults()
|
||||
t.Logf("After: %v", x)
|
||||
var expected interface{}
|
||||
err = json.Unmarshal([]byte(`{
|
||||
"int": 42,
|
||||
"str": "Hello",
|
||||
"obj": {"foo": "bar"},
|
||||
"nested": {"inner": 7},
|
||||
"all": {"foo": 42, "bar": 42},
|
||||
"any": {"foo": 42},
|
||||
"one": {"bar": 42}
|
||||
}`), &expected)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, x)
|
||||
}
|
||||
101
vendor/github.com/go-openapi/validate/fixtures/defaulting/schema.json
generated
vendored
Normal file
101
vendor/github.com/go-openapi/validate/fixtures/defaulting/schema.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"properties": {
|
||||
"int": {
|
||||
"type": "integer",
|
||||
"default": 42
|
||||
},
|
||||
"str": {
|
||||
"type": "string",
|
||||
"minLength": 4,
|
||||
"default": "Hello"
|
||||
},
|
||||
"obj": {
|
||||
"type": "object",
|
||||
"default": {"foo": "bar"}
|
||||
},
|
||||
"nested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"inner": {
|
||||
"type": "integer",
|
||||
"default": 7
|
||||
}
|
||||
}
|
||||
},
|
||||
"all": {
|
||||
"allOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "integer",
|
||||
"default": 42
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "integer",
|
||||
"default": 42
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"any": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "integer",
|
||||
"default": 42
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "integer",
|
||||
"default": 42
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"one": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": ["foo"]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "integer",
|
||||
"default": 42
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"not": {
|
||||
"not": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"foo": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["int", "str", "nested", "all", "any", "one"]
|
||||
}
|
||||
32
vendor/github.com/go-openapi/validate/object_validator.go
generated
vendored
32
vendor/github.com/go-openapi/validate/object_validator.go
generated
vendored
@@ -64,14 +64,6 @@ func (o *objectValidator) Validate(data interface{}) *Result {
|
||||
}
|
||||
|
||||
res := new(Result)
|
||||
if len(o.Required) > 0 {
|
||||
for _, k := range o.Required {
|
||||
if _, ok := val[k]; !ok {
|
||||
res.AddErrors(errors.Required(o.Path+"."+k, o.In))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if o.AdditionalProperties != nil && !o.AdditionalProperties.Allows {
|
||||
for k := range val {
|
||||
@@ -102,6 +94,8 @@ func (o *objectValidator) Validate(data interface{}) *Result {
|
||||
}
|
||||
}
|
||||
|
||||
createdFromDefaults := map[string]bool{}
|
||||
|
||||
for pName, pSchema := range o.Properties {
|
||||
rName := pName
|
||||
if o.Path != "" {
|
||||
@@ -109,7 +103,24 @@ func (o *objectValidator) Validate(data interface{}) *Result {
|
||||
}
|
||||
|
||||
if v, ok := val[pName]; ok {
|
||||
res.Merge(NewSchemaValidator(&pSchema, o.Root, rName, o.KnownFormats).Validate(v))
|
||||
r := NewSchemaValidator(&pSchema, o.Root, rName, o.KnownFormats).Validate(v)
|
||||
res.Merge(r)
|
||||
} else if pSchema.Default != nil {
|
||||
createdFromDefaults[pName] = true
|
||||
pName := pName // shaddow
|
||||
def := pSchema.Default
|
||||
res.Defaulters = append(res.Defaulters, DefaulterFunc(func() {
|
||||
val[pName] = def
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.Required) > 0 {
|
||||
for _, k := range o.Required {
|
||||
if _, ok := val[k]; !ok && !createdFromDefaults[k] {
|
||||
res.AddErrors(errors.Required(o.Path+"."+k, o.In))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,9 +151,6 @@ func (o *objectValidator) validatePatternProperty(key string, value interface{},
|
||||
|
||||
res := validator.Validate(value)
|
||||
result.Merge(res)
|
||||
if res.IsValid() {
|
||||
succeededOnce = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
vendor/github.com/go-openapi/validate/result.go
generated
vendored
18
vendor/github.com/go-openapi/validate/result.go
generated
vendored
@@ -25,10 +25,21 @@ var (
|
||||
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
|
||||
@@ -38,6 +49,7 @@ func (r *Result) Merge(other *Result) *Result {
|
||||
}
|
||||
r.AddErrors(other.Errors...)
|
||||
r.MatchCount += other.MatchCount
|
||||
r.Defaulters = append(r.Defaulters, other.Defaulters...)
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -69,3 +81,9 @@ func (r *Result) AsError() error {
|
||||
}
|
||||
return errors.CompositeValidationError(r.Errors...)
|
||||
}
|
||||
|
||||
func (r *Result) ApplyDefaults() {
|
||||
for _, d := range r.Defaulters {
|
||||
d.Apply()
|
||||
}
|
||||
}
|
||||
|
||||
3
vendor/github.com/go-openapi/validate/schema.go
generated
vendored
3
vendor/github.com/go-openapi/validate/schema.go
generated
vendored
@@ -148,7 +148,6 @@ func (s *SchemaValidator) commonValidator() valueValidator {
|
||||
return &basicCommonValidator{
|
||||
Path: s.Path,
|
||||
In: s.in,
|
||||
Default: s.Schema.Default,
|
||||
Enum: s.Schema.Enum,
|
||||
}
|
||||
}
|
||||
@@ -184,7 +183,6 @@ func (s *SchemaValidator) stringValidator() valueValidator {
|
||||
return &stringValidator{
|
||||
Path: s.Path,
|
||||
In: s.in,
|
||||
Default: s.Schema.Default,
|
||||
MaxLength: s.Schema.MaxLength,
|
||||
MinLength: s.Schema.MinLength,
|
||||
Pattern: s.Schema.Pattern,
|
||||
@@ -195,7 +193,6 @@ func (s *SchemaValidator) formatValidator() valueValidator {
|
||||
return &formatValidator{
|
||||
Path: s.Path,
|
||||
In: s.in,
|
||||
//Default: s.Schema.Default,
|
||||
Format: s.Schema.Format,
|
||||
KnownFormats: s.KnownFormats,
|
||||
}
|
||||
|
||||
12
vendor/github.com/go-openapi/validate/schema_props.go
generated
vendored
12
vendor/github.com/go-openapi/validate/schema_props.go
generated
vendored
@@ -89,6 +89,7 @@ func (s *schemaPropsValidator) Applies(source interface{}, kind reflect.Kind) bo
|
||||
|
||||
func (s *schemaPropsValidator) Validate(data interface{}) *Result {
|
||||
mainResult := new(Result)
|
||||
var firstSuccess *Result
|
||||
if len(s.anyOfValidators) > 0 {
|
||||
var bestFailures *Result
|
||||
succeededOnce := false
|
||||
@@ -97,6 +98,9 @@ func (s *schemaPropsValidator) Validate(data interface{}) *Result {
|
||||
if result.IsValid() {
|
||||
bestFailures = nil
|
||||
succeededOnce = true
|
||||
if firstSuccess == nil {
|
||||
firstSuccess = result
|
||||
}
|
||||
break
|
||||
}
|
||||
if bestFailures == nil || result.MatchCount > bestFailures.MatchCount {
|
||||
@@ -109,11 +113,14 @@ func (s *schemaPropsValidator) Validate(data interface{}) *Result {
|
||||
}
|
||||
if bestFailures != nil {
|
||||
mainResult.Merge(bestFailures)
|
||||
} else if firstSuccess != nil {
|
||||
mainResult.Merge(firstSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
if len(s.oneOfValidators) > 0 {
|
||||
var bestFailures *Result
|
||||
var firstSuccess *Result
|
||||
validated := 0
|
||||
|
||||
for _, oneOfSchema := range s.oneOfValidators {
|
||||
@@ -121,6 +128,9 @@ func (s *schemaPropsValidator) Validate(data interface{}) *Result {
|
||||
if result.IsValid() {
|
||||
validated++
|
||||
bestFailures = nil
|
||||
if firstSuccess == nil {
|
||||
firstSuccess = result
|
||||
}
|
||||
continue
|
||||
}
|
||||
if validated == 0 && (bestFailures == nil || result.MatchCount > bestFailures.MatchCount) {
|
||||
@@ -133,6 +143,8 @@ func (s *schemaPropsValidator) Validate(data interface{}) *Result {
|
||||
if bestFailures != nil {
|
||||
mainResult.Merge(bestFailures)
|
||||
}
|
||||
} else if firstSuccess != nil {
|
||||
mainResult.Merge(firstSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user