forked from forgejo/forgejo
[Vendor] update go-swagger v0.21.0 -> v0.25.0 (#12670)
* Update go-swagger * vendor
This commit is contained in:
parent
66843f2237
commit
3270e7a443
350 changed files with 26353 additions and 5552 deletions
71
vendor/github.com/go-openapi/validate/object_validator.go
generated
vendored
71
vendor/github.com/go-openapi/validate/object_validator.go
generated
vendored
|
@ -51,40 +51,54 @@ func (o *objectValidator) Applies(source interface{}, kind reflect.Kind) bool {
|
|||
return r
|
||||
}
|
||||
|
||||
func (o *objectValidator) isPropertyName() bool {
|
||||
func (o *objectValidator) isProperties() bool {
|
||||
p := strings.Split(o.Path, ".")
|
||||
return p[len(p)-1] == "properties" && p[len(p)-2] != "properties"
|
||||
return len(p) > 1 && p[len(p)-1] == jsonProperties && p[len(p)-2] != jsonProperties
|
||||
}
|
||||
|
||||
func (o *objectValidator) isDefault() bool {
|
||||
p := strings.Split(o.Path, ".")
|
||||
return len(p) > 1 && p[len(p)-1] == jsonDefault && p[len(p)-2] != jsonDefault
|
||||
}
|
||||
|
||||
func (o *objectValidator) isExample() bool {
|
||||
p := strings.Split(o.Path, ".")
|
||||
return len(p) > 1 && (p[len(p)-1] == swaggerExample || p[len(p)-1] == swaggerExamples) && p[len(p)-2] != swaggerExample
|
||||
}
|
||||
|
||||
func (o *objectValidator) checkArrayMustHaveItems(res *Result, val map[string]interface{}) {
|
||||
if t, typeFound := val["type"]; typeFound {
|
||||
if tpe, ok := t.(string); ok && tpe == "array" {
|
||||
if _, itemsKeyFound := val["items"]; !itemsKeyFound {
|
||||
res.AddErrors(errors.Required("items", o.Path))
|
||||
// for swagger 2.0 schemas, there is an additional constraint to have array items defined explicitly.
|
||||
// with pure jsonschema draft 4, one may have arrays with undefined items (i.e. any type).
|
||||
if t, typeFound := val[jsonType]; typeFound {
|
||||
if tpe, ok := t.(string); ok && tpe == arrayType {
|
||||
if item, itemsKeyFound := val[jsonItems]; !itemsKeyFound {
|
||||
res.AddErrors(errors.Required(jsonItems, o.Path, item))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *objectValidator) checkItemsMustBeTypeArray(res *Result, val map[string]interface{}) {
|
||||
if !o.isPropertyName() {
|
||||
if _, itemsKeyFound := val["items"]; itemsKeyFound {
|
||||
t, typeFound := val["type"]
|
||||
if !o.isProperties() && !o.isDefault() && !o.isExample() {
|
||||
if _, itemsKeyFound := val[jsonItems]; itemsKeyFound {
|
||||
t, typeFound := val[jsonType]
|
||||
if typeFound {
|
||||
if tpe, ok := t.(string); !ok || tpe != "array" {
|
||||
res.AddErrors(errors.InvalidType(o.Path, o.In, "array", nil))
|
||||
if tpe, ok := t.(string); !ok || tpe != arrayType {
|
||||
res.AddErrors(errors.InvalidType(o.Path, o.In, arrayType, nil))
|
||||
}
|
||||
} else {
|
||||
// there is no type
|
||||
res.AddErrors(errors.Required("type", o.Path))
|
||||
res.AddErrors(errors.Required(jsonType, o.Path, t))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *objectValidator) precheck(res *Result, val map[string]interface{}) {
|
||||
o.checkArrayMustHaveItems(res, val)
|
||||
if !o.Options.DisableObjectArrayTypeCheck {
|
||||
if o.Options.EnableArrayMustHaveItemsCheck {
|
||||
o.checkArrayMustHaveItems(res, val)
|
||||
}
|
||||
if o.Options.EnableObjectArrayTypeCheck {
|
||||
o.checkItemsMustBeTypeArray(res, val)
|
||||
}
|
||||
}
|
||||
|
@ -134,21 +148,18 @@ func (o *objectValidator) Validate(data interface{}) *Result {
|
|||
// NOTE: prefix your messages here by "IMPORTANT!" so there are not filtered
|
||||
// by higher level callers (the IMPORTANT! tag will be eventually
|
||||
// removed).
|
||||
switch k {
|
||||
// $ref is forbidden in header
|
||||
case "headers":
|
||||
if val[k] != nil {
|
||||
if headers, mapOk := val[k].(map[string]interface{}); mapOk {
|
||||
for headerKey, headerBody := range headers {
|
||||
if headerBody != nil {
|
||||
if headerSchema, mapOfMapOk := headerBody.(map[string]interface{}); mapOfMapOk {
|
||||
if _, found := headerSchema["$ref"]; found {
|
||||
var msg string
|
||||
if refString, stringOk := headerSchema["$ref"].(string); stringOk {
|
||||
msg = strings.Join([]string{", one may not use $ref=\":", refString, "\""}, "")
|
||||
}
|
||||
res.AddErrors(refNotAllowedInHeaderMsg(o.Path, headerKey, msg))
|
||||
if k == "headers" && val[k] != nil {
|
||||
// $ref is forbidden in header
|
||||
if headers, mapOk := val[k].(map[string]interface{}); mapOk {
|
||||
for headerKey, headerBody := range headers {
|
||||
if headerBody != nil {
|
||||
if headerSchema, mapOfMapOk := headerBody.(map[string]interface{}); mapOfMapOk {
|
||||
if _, found := headerSchema["$ref"]; found {
|
||||
var msg string
|
||||
if refString, stringOk := headerSchema["$ref"].(string); stringOk {
|
||||
msg = strings.Join([]string{", one may not use $ref=\":", refString, "\""}, "")
|
||||
}
|
||||
res.AddErrors(refNotAllowedInHeaderMsg(o.Path, headerKey, msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,8 +227,8 @@ func (o *objectValidator) Validate(data interface{}) *Result {
|
|||
// Check required properties
|
||||
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))
|
||||
if v, ok := val[k]; !ok && !createdFromDefaults[k] {
|
||||
res.AddErrors(errors.Required(o.Path+"."+k, o.In, v))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue