mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Handle some incorrect type values like 'int' and 'bool' in setters
This commit is contained in:
@@ -242,6 +242,7 @@ func (s *Set) set(field *yaml.RNode, ext *CliExtension, sch *spec.Schema) (bool,
|
||||
// validateAgainstSchema validates the input setter value against user provided
|
||||
// openAI schema
|
||||
func validateAgainstSchema(ext *CliExtension, sch *spec.Schema) error {
|
||||
fixSchemaTypes(sch)
|
||||
sc := spec.Schema{}
|
||||
sc.Properties = map[string]spec.Schema{}
|
||||
sc.Properties[ext.Setter.Name] = *sch
|
||||
@@ -301,6 +302,33 @@ func validateAgainstSchema(ext *CliExtension, sch *spec.Schema) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// fixSchemaTypes traverses the schema and checks for some common
|
||||
// errors for the type field. This currently involves users using
|
||||
// 'int' instead of 'integer' and 'bool' instead of 'boolean'. Early versions
|
||||
// of setters didn't validate this, so there are users that have invalid
|
||||
// types in their packages.
|
||||
func fixSchemaTypes(sc *spec.Schema) {
|
||||
for i := range sc.Type {
|
||||
currentType := sc.Type[i]
|
||||
if currentType == "int" {
|
||||
sc.Type[i] = "integer"
|
||||
}
|
||||
if currentType == "bool" {
|
||||
sc.Type[i] = "boolean"
|
||||
}
|
||||
}
|
||||
|
||||
if items := sc.Items; items != nil {
|
||||
if items.Schema != nil {
|
||||
fixSchemaTypes(items.Schema)
|
||||
}
|
||||
for i := range items.Schemas {
|
||||
schema := items.Schemas[i]
|
||||
fixSchemaTypes(&schema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetOpenAPI updates a setter value
|
||||
type SetOpenAPI struct {
|
||||
// Name is the name of the setter to add
|
||||
|
||||
Reference in New Issue
Block a user