Skip to content

Commit a0b9617

Browse files
committed
Don't use a string as the OpenAPI default value for Helm values with 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 `{}`. Signed-off-by: Giuseppe Capizzi <[email protected]>
1 parent 0972b2f commit a0b9617

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (h HelmValuesSchemaGen) calculateProperties(key *yaml3.Node, value *yaml3.N
180180
if len(properties) > 0 {
181181
apiKeys = append(apiKeys, &MapItem{Key: propertiesKey, Value: &Map{Items: properties}})
182182
} else {
183-
apiKeys = append(apiKeys, &MapItem{Key: defaultKey, Value: "{}"})
183+
apiKeys = append(apiKeys, &MapItem{Key: defaultKey, Value: &Map{}})
184184
}
185185
case yaml3.SequenceNode:
186186
apiKeys = append(apiKeys, &MapItem{Key: typeKey, Value: arrayVal})

cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ arrExample:
8181
floatExample: 2.3
8282
# Integer example
8383
intExample: 3
84+
# Object example
85+
objExample: {}
8486
`,
8587
want: `properties:
8688
arrExample:
@@ -111,6 +113,10 @@ intExample: 3
111113
default: test-container
112114
description: Container name
113115
type: string
116+
objExample:
117+
default: {}
118+
description: Object example
119+
type: object
114120
type: object
115121
`},
116122
{

cli/test/e2e/package_authoring_e2e_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ spec:
260260
operator:
261261
properties:
262262
affinity:
263-
default: '{}'
263+
default: {}
264264
type: object
265265
createOperatorServiceAccount:
266266
default: true
@@ -281,7 +281,7 @@ spec:
281281
objects like Deployment, ServiceAccount, Role etc.
282282
type: string
283283
nodeSelector:
284-
default: '{}'
284+
default: {}
285285
type: object
286286
operator_image_name:
287287
default: mongodb-enterprise-operator
@@ -817,7 +817,7 @@ spec:
817817
default: ""
818818
type: string
819819
podAnnotations:
820-
default: '{}'
820+
default: {}
821821
type: object
822822
replicaCount:
823823
default: 1
@@ -834,7 +834,7 @@ spec:
834834
serviceAccount:
835835
properties:
836836
annotations:
837-
default: '{}'
837+
default: {}
838838
description: Annotations to add to the service account
839839
type: object
840840
create:

0 commit comments

Comments
 (0)