Update all dependencies

Note: should we ditch vendoring?

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-09-29 10:20:26 +00:00 committed by Gabriel
parent 22fde8d30e
commit 0093393bc3
371 changed files with 91052 additions and 25816 deletions

View file

@ -33,7 +33,7 @@ type objectValidator struct {
Properties map[string]spec.Schema
AdditionalProperties *spec.SchemaOrBool
PatternProperties map[string]spec.Schema
Root interface{}
Root any
KnownFormats strfmt.Registry
Options *SchemaValidatorOptions
splitPath []string
@ -42,7 +42,7 @@ type objectValidator struct {
func newObjectValidator(path, in string,
maxProperties, minProperties *int64, required []string, properties spec.SchemaProperties,
additionalProperties *spec.SchemaOrBool, patternProperties spec.SchemaProperties,
root interface{}, formats strfmt.Registry, opts *SchemaValidatorOptions) *objectValidator {
root any, formats strfmt.Registry, opts *SchemaValidatorOptions) *objectValidator {
if opts == nil {
opts = new(SchemaValidatorOptions)
}
@ -70,104 +70,17 @@ func newObjectValidator(path, in string,
return v
}
func (o *objectValidator) SetPath(path string) {
o.Path = path
o.splitPath = strings.Split(path, ".")
}
func (o *objectValidator) Applies(source interface{}, kind reflect.Kind) bool {
// TODO: this should also work for structs
// there is a problem in the type validator where it will be unhappy about null values
// so that requires more testing
_, isSchema := source.(*spec.Schema)
return isSchema && (kind == reflect.Map || kind == reflect.Struct)
}
func (o *objectValidator) isProperties() bool {
p := o.splitPath
return len(p) > 1 && p[len(p)-1] == jsonProperties && p[len(p)-2] != jsonProperties
}
func (o *objectValidator) isDefault() bool {
p := o.splitPath
return len(p) > 1 && p[len(p)-1] == jsonDefault && p[len(p)-2] != jsonDefault
}
func (o *objectValidator) isExample() bool {
p := o.splitPath
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{}) {
// 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 val == nil {
return
}
t, typeFound := val[jsonType]
if !typeFound {
return
}
tpe, isString := t.(string)
if !isString || tpe != arrayType {
return
}
item, itemsKeyFound := val[jsonItems]
if itemsKeyFound {
return
}
res.AddErrors(errors.Required(jsonItems, o.Path, item))
}
func (o *objectValidator) checkItemsMustBeTypeArray(res *Result, val map[string]interface{}) {
if val == nil {
return
}
if o.isProperties() || o.isDefault() || o.isExample() {
return
}
_, itemsKeyFound := val[jsonItems]
if !itemsKeyFound {
return
}
t, typeFound := val[jsonType]
if !typeFound {
// there is no type
res.AddErrors(errors.Required(jsonType, o.Path, t))
}
if tpe, isString := t.(string); !isString || tpe != arrayType {
res.AddErrors(errors.InvalidType(o.Path, o.In, arrayType, nil))
}
}
func (o *objectValidator) precheck(res *Result, val map[string]interface{}) {
if o.Options.EnableArrayMustHaveItemsCheck {
o.checkArrayMustHaveItems(res, val)
}
if o.Options.EnableObjectArrayTypeCheck {
o.checkItemsMustBeTypeArray(res, val)
}
}
func (o *objectValidator) Validate(data interface{}) *Result {
func (o *objectValidator) Validate(data any) *Result {
if o.Options.recycleValidators {
defer func() {
o.redeem()
}()
}
var val map[string]interface{}
var val map[string]any
if data != nil {
var ok bool
val, ok = data.(map[string]interface{})
val, ok = data.(map[string]any)
if !ok {
return errorHelp.sErr(invalidObjectMsg(o.Path, o.In), o.Options.recycleResult)
}
@ -213,7 +126,7 @@ func (o *objectValidator) Validate(data interface{}) *Result {
for _, pName := range patterns {
if v, ok := o.PatternProperties[pName]; ok {
r := newSchemaValidator(&v, o.Root, o.Path+"."+key, o.KnownFormats, o.Options).Validate(value)
res.mergeForField(data.(map[string]interface{}), key, r)
res.mergeForField(data.(map[string]any), key, r)
}
}
}
@ -221,7 +134,94 @@ func (o *objectValidator) Validate(data interface{}) *Result {
return res
}
func (o *objectValidator) validateNoAdditionalProperties(val map[string]interface{}, res *Result) {
func (o *objectValidator) SetPath(path string) {
o.Path = path
o.splitPath = strings.Split(path, ".")
}
func (o *objectValidator) Applies(source any, kind reflect.Kind) bool {
// TODO: this should also work for structs
// there is a problem in the type validator where it will be unhappy about null values
// so that requires more testing
_, isSchema := source.(*spec.Schema)
return isSchema && (kind == reflect.Map || kind == reflect.Struct)
}
func (o *objectValidator) isProperties() bool {
p := o.splitPath
return len(p) > 1 && p[len(p)-1] == jsonProperties && p[len(p)-2] != jsonProperties
}
func (o *objectValidator) isDefault() bool {
p := o.splitPath
return len(p) > 1 && p[len(p)-1] == jsonDefault && p[len(p)-2] != jsonDefault
}
func (o *objectValidator) isExample() bool {
p := o.splitPath
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]any) {
// 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 val == nil {
return
}
t, typeFound := val[jsonType]
if !typeFound {
return
}
tpe, isString := t.(string)
if !isString || tpe != arrayType {
return
}
item, itemsKeyFound := val[jsonItems]
if itemsKeyFound {
return
}
res.AddErrors(errors.Required(jsonItems, o.Path, item))
}
func (o *objectValidator) checkItemsMustBeTypeArray(res *Result, val map[string]any) {
if val == nil {
return
}
if o.isProperties() || o.isDefault() || o.isExample() {
return
}
_, itemsKeyFound := val[jsonItems]
if !itemsKeyFound {
return
}
t, typeFound := val[jsonType]
if !typeFound {
// there is no type
res.AddErrors(errors.Required(jsonType, o.Path, t))
}
if tpe, isString := t.(string); !isString || tpe != arrayType {
res.AddErrors(errors.InvalidType(o.Path, o.In, arrayType, nil))
}
}
func (o *objectValidator) precheck(res *Result, val map[string]any) {
if o.Options.EnableArrayMustHaveItemsCheck {
o.checkArrayMustHaveItems(res, val)
}
if o.Options.EnableObjectArrayTypeCheck {
o.checkItemsMustBeTypeArray(res, val)
}
}
func (o *objectValidator) validateNoAdditionalProperties(val map[string]any, res *Result) {
for k := range val {
if k == "$schema" || k == "id" {
// special properties "$schema" and "id" are ignored
@ -266,7 +266,7 @@ func (o *objectValidator) validateNoAdditionalProperties(val map[string]interfac
}
// $ref is forbidden in header
headers, mapOk := val[k].(map[string]interface{})
headers, mapOk := val[k].(map[string]any)
if !mapOk {
continue
}
@ -276,7 +276,7 @@ func (o *objectValidator) validateNoAdditionalProperties(val map[string]interfac
continue
}
headerSchema, mapOfMapOk := headerBody.(map[string]interface{})
headerSchema, mapOfMapOk := headerBody.(map[string]any)
if !mapOfMapOk {
continue
}
@ -303,7 +303,7 @@ func (o *objectValidator) validateNoAdditionalProperties(val map[string]interfac
}
}
func (o *objectValidator) validateAdditionalProperties(val map[string]interface{}, res *Result) {
func (o *objectValidator) validateAdditionalProperties(val map[string]any, res *Result) {
for key, value := range val {
_, regularProperty := o.Properties[key]
if regularProperty {
@ -331,7 +331,7 @@ func (o *objectValidator) validateAdditionalProperties(val map[string]interface{
// Valid cases: additionalProperties: true or undefined
}
func (o *objectValidator) validatePropertiesSchema(val map[string]interface{}, res *Result) {
func (o *objectValidator) validatePropertiesSchema(val map[string]any, res *Result) {
createdFromDefaults := map[string]struct{}{}
// Property types:
@ -389,7 +389,7 @@ func (o *objectValidator) validatePropertiesSchema(val map[string]interface{}, r
}
// TODO: succeededOnce is not used anywhere
func (o *objectValidator) validatePatternProperty(key string, value interface{}, result *Result) (bool, bool, []string) {
func (o *objectValidator) validatePatternProperty(key string, value any, result *Result) (bool, bool, []string) {
if len(o.PatternProperties) == 0 {
return false, false, nil
}