From 0329546f58de871871a2b3bb2a641fab47bd3892 Mon Sep 17 00:00:00 2001 From: Giuseppe Capizzi Date: Thu, 18 Jan 2024 17:02:14 +0000 Subject: [PATCH] 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 `{}`. --- .../release/schemagenerator/helm_openapi_schema_gen.go | 4 +++- .../release/schemagenerator/helm_openapi_schema_gen_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen.go b/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen.go index 83d8469c45..85f6aa2dd3 100644 --- a/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen.go +++ b/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen.go @@ -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}) @@ -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}) diff --git a/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen_test.go b/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen_test.go index 571b83c350..2006c3b8ca 100644 --- a/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen_test.go +++ b/cli/pkg/kctrl/cmd/package/release/schemagenerator/helm_openapi_schema_gen_test.go @@ -81,6 +81,8 @@ arrExample: floatExample: 2.3 # Integer example intExample: 3 +# Object example +objExample: {} `, want: `properties: arrExample: @@ -111,6 +113,10 @@ intExample: 3 default: test-container description: Container name type: string + objExample: + default: {} + description: Object example + type: object type: object `}, {