Skip to content

Commit

Permalink
Don't use a string as the OpenAPI default value for Helm values with …
Browse files Browse the repository at this point in the history
…an empty object default

This fixes the translation of empty object Helm default values into
OpenAPI. Empty objects were getting the string `"{}"` as their default,
which is not a valid value. We now correctly use `{}`.
  • Loading branch information
gcapizzi committed Jan 18, 2024
1 parent 0972b2f commit 0329546
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func (h HelmValuesSchemaGen) calculateProperties(key *yaml3.Node, value *yaml3.N

switch value.Kind {
case yaml3.MappingNode:
fmt.Printf("%#v => %#v\n", key, value)

var properties []*MapItem
apiKeys = append(apiKeys, &MapItem{Key: typeKey, Value: objectVal})

Expand All @@ -180,7 +182,7 @@ func (h HelmValuesSchemaGen) calculateProperties(key *yaml3.Node, value *yaml3.N
if len(properties) > 0 {
apiKeys = append(apiKeys, &MapItem{Key: propertiesKey, Value: &Map{Items: properties}})
} else {
apiKeys = append(apiKeys, &MapItem{Key: defaultKey, Value: "{}"})
apiKeys = append(apiKeys, &MapItem{Key: defaultKey, Value: &Map{}})
}
case yaml3.SequenceNode:
apiKeys = append(apiKeys, &MapItem{Key: typeKey, Value: arrayVal})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ arrExample:
floatExample: 2.3
# Integer example
intExample: 3
# Object example
objExample: {}
`,
want: `properties:
arrExample:
Expand Down Expand Up @@ -111,6 +113,10 @@ intExample: 3
default: test-container
description: Container name
type: string
objExample:
default: {}
description: Object example
type: object
type: object
`},
{
Expand Down

0 comments on commit 0329546

Please sign in to comment.