From 6dfe2878ecd784afc2753bd5b9fbb59f4f0a3638 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Sat, 28 Dec 2024 19:12:45 +0100 Subject: [PATCH] feat: Add dont-add-global flag --- README.md | 1 + cmd/helm-schema/cli.go | 2 ++ cmd/helm-schema/main.go | 2 ++ pkg/schema/schema.go | 4 +++- pkg/schema/worker.go | 4 ++-- pkg/schema/worker_test.go | 2 ++ 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 56950c0..4f9b092 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Flags: -a, --append-newline "append newline to generated jsonschema at the end of the file" -c, --chart-search-root string "directory to search recursively within for charts (default ".")" -i, --dependencies-filter strings "only generate schema for specified dependencies (comma-separated list of dependency names)" + -g, --dont-add-global "dont auto add global property" -x, --dont-strip-helm-docs-prefix "disable the removal of the helm-docs prefix (--)" -d, --dry-run "don't actually create files just print to stdout passed" -p, --helm-docs-compatibility-mode "parse and use helm-docs comments" diff --git a/cmd/helm-schema/cli.go b/cmd/helm-schema/cli.go index 1ad1383..a756461 100644 --- a/cmd/helm-schema/cli.go +++ b/cmd/helm-schema/cli.go @@ -73,6 +73,8 @@ func newCommand(run func(cmd *cobra.Command, args []string) error) (*cobra.Comma StringSliceP("skip-auto-generation", "k", []string{}, "comma separated list of fields to skip from being created by default (possible: title, description, required, default, additionalProperties)") cmd.PersistentFlags(). StringSliceP("dependencies-filter", "i", []string{}, "only generate schema for specified dependencies (comma-separated list of dependency names)") + cmd.PersistentFlags(). + BoolP("dont-add-global", "g", false, "dont auto add global property") viper.AutomaticEnv() viper.SetEnvPrefix("HELM_SCHEMA") diff --git a/cmd/helm-schema/main.go b/cmd/helm-schema/main.go index 9bca7ff..117ad34 100644 --- a/cmd/helm-schema/main.go +++ b/cmd/helm-schema/main.go @@ -77,6 +77,7 @@ func exec(cmd *cobra.Command, _ []string) error { appendNewline := viper.GetBool("append-newline") dependenciesFilter := viper.GetStringSlice("dependencies-filter") dependenciesFilterMap := make(map[string]bool) + dontAddGlobal := viper.GetBool("dont-add-global") for _, dep := range dependenciesFilter { dependenciesFilterMap[dep] = true } @@ -119,6 +120,7 @@ func exec(cmd *cobra.Command, _ []string) error { keepFullComment, helmDocsCompatibilityMode, dontRemoveHelmDocsPrefix, + dontAddGlobal, valueFileNames, skipConfig, outFile, diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 3042fc5..9a84648 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -770,6 +770,7 @@ func YamlToSchema( keepFullComment bool, helmDocsCompatibilityMode bool, dontRemoveHelmDocsPrefix bool, + dontAddGlobal bool, skipAutoGeneration *SkipAutoGenerationConfig, parentRequiredProperties *[]string, ) *Schema { @@ -788,11 +789,12 @@ func YamlToSchema( keepFullComment, helmDocsCompatibilityMode, dontRemoveHelmDocsPrefix, + dontAddGlobal, skipAutoGeneration, &schema.Required.Strings, ).Properties - if _, ok := schema.Properties["global"]; !ok { + if _, ok := schema.Properties["global"]; !ok && !dontAddGlobal { // global key must be present, otherwise helm lint will fail if schema.Properties == nil { schema.Properties = make(map[string]*Schema) diff --git a/pkg/schema/worker.go b/pkg/schema/worker.go index 03a0b00..da3d8cc 100644 --- a/pkg/schema/worker.go +++ b/pkg/schema/worker.go @@ -21,7 +21,7 @@ type Result struct { } func Worker( - dryRun, uncomment, addSchemaReference, keepFullComment, helmDocsCompatibilityMode, dontRemoveHelmDocsPrefix bool, + dryRun, uncomment, addSchemaReference, keepFullComment, helmDocsCompatibilityMode, dontRemoveHelmDocsPrefix, dontAddGlobal bool, valueFileNames []string, skipAutoGenerationConfig *SkipAutoGenerationConfig, outFile string, @@ -117,7 +117,7 @@ func Worker( continue } - result.Schema = *YamlToSchema(valuesPath, &values, keepFullComment, helmDocsCompatibilityMode, dontRemoveHelmDocsPrefix, skipAutoGenerationConfig, nil) + result.Schema = *YamlToSchema(valuesPath, &values, keepFullComment, helmDocsCompatibilityMode, dontRemoveHelmDocsPrefix, dontAddGlobal, skipAutoGenerationConfig, nil) results <- result } diff --git a/pkg/schema/worker_test.go b/pkg/schema/worker_test.go index ce6c004..efd64b4 100644 --- a/pkg/schema/worker_test.go +++ b/pkg/schema/worker_test.go @@ -20,6 +20,7 @@ func TestWorker(t *testing.T) { keepFullComment bool helmDocsCompatibilityMode bool dontRemoveHelmDocsPrefix bool + dontAddGlobal bool skipAutoGenerationConfig *SkipAutoGenerationConfig outFile string expectedErrors bool @@ -128,6 +129,7 @@ key1: value1 tt.keepFullComment, tt.helmDocsCompatibilityMode, tt.dontRemoveHelmDocsPrefix, + tt.dontAddGlobal, tt.valueFileNames, tt.skipAutoGenerationConfig, tt.outFile,