Skip to content

Commit

Permalink
Flatten empty custom vars of type array & map correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jun 19, 2023
1 parent 990583d commit 8692f72
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/flatten/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ func Flatten(value interface{}, prefix string) map[string]interface{} {
flatten = func(key string, value interface{}) {
switch value := value.(type) {
case map[string]interface{}:
if len(value) == 0 {
flattened[key+"."] = nil
break
}

for k, v := range value {
flatten(key+"."+k, v)
}
case []interface{}:
if len(value) == 0 {
flattened[key+"[]"] = nil
break
}

for i, v := range value {
flatten(key+"["+strconv.Itoa(i)+"]", v)
}
Expand Down

0 comments on commit 8692f72

Please sign in to comment.