Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cyclops-ctrl/internal/mapper/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
)

func HelmSchemaToFields(name string, schema helm.Property, defs map[string]helm.Property, dependencies []*models.Template) models.Field {
if shouldResolvePropertyComposition(schema) {
return HelmSchemaToFields(name, resolvePropertyComposition(schema), defs, dependencies)
}

if schema.Type == "array" {
return models.Field{
Name: name,
Expand Down Expand Up @@ -211,3 +215,26 @@ func resolveJSONSchemaRef(defs map[string]helm.Property, ref []string) helm.Prop

return resolveJSONSchemaRef(def.Properties, ref[1:])
}

func shouldResolvePropertyComposition(schema helm.Property) bool {
return len(schema.AnyOf) != 0
}

func resolvePropertyComposition(schema helm.Property) helm.Property {
if len(schema.AnyOf) == 0 {
return schema
}

// go over all options of anyOf and if there is a boolean version, return it.
// If a field can be represented with a boolean we should use it since it is
// the easiest way to input a correct value.
//
// If there are multiple boolean anyOfs, return the first one.
for _, p := range schema.AnyOf {
if p.Type == "boolean" {
return p
}
}

return schema.AnyOf[0]
}
3 changes: 3 additions & 0 deletions cyclops-ctrl/internal/models/helm/helmschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Property struct {
MinLength *int `json:"minLength"`
MaxLength *int `json:"maxLength"`
Pattern *string `json:"pattern"`

// schema compositions
AnyOf []Property `json:"anyOf"`
}

type PropertyType string
Expand Down
Loading