Skip to content

Commit

Permalink
feat: Add dont-add-global flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Dec 28, 2024
1 parent 39bcce7 commit 6dfe287
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions cmd/helm-schema/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions cmd/helm-schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -119,6 +120,7 @@ func exec(cmd *cobra.Command, _ []string) error {
keepFullComment,
helmDocsCompatibilityMode,
dontRemoveHelmDocsPrefix,
dontAddGlobal,
valueFileNames,
skipConfig,
outFile,
Expand Down
4 changes: 3 additions & 1 deletion pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ func YamlToSchema(
keepFullComment bool,
helmDocsCompatibilityMode bool,
dontRemoveHelmDocsPrefix bool,
dontAddGlobal bool,
skipAutoGeneration *SkipAutoGenerationConfig,
parentRequiredProperties *[]string,
) *Schema {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/schema/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/schema/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestWorker(t *testing.T) {
keepFullComment bool
helmDocsCompatibilityMode bool
dontRemoveHelmDocsPrefix bool
dontAddGlobal bool
skipAutoGenerationConfig *SkipAutoGenerationConfig
outFile string
expectedErrors bool
Expand Down Expand Up @@ -128,6 +129,7 @@ key1: value1
tt.keepFullComment,
tt.helmDocsCompatibilityMode,
tt.dontRemoveHelmDocsPrefix,
tt.dontAddGlobal,
tt.valueFileNames,
tt.skipAutoGenerationConfig,
tt.outFile,
Expand Down

0 comments on commit 6dfe287

Please sign in to comment.