Skip to content

Commit

Permalink
fix helm docs omitChildren json file name override (#430)
Browse files Browse the repository at this point in the history
* fix helm docs omitChildren json file name override

* changelog
  • Loading branch information
Albert authored Mar 8, 2023
1 parent 7fa57b0 commit 1e261f8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/v0.28.3/omitChildren-helm-docs-gen-bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: FIX
description: Fixes bug where the helm documentation's field name would be wrong if the tag omitChildren and json are both used
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/7833
8 changes: 7 additions & 1 deletion codegen/doc/helm_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ func docReflect(addValue addValue, path []string, desc string, typ reflect.Type,

// ignore the children of fields that are marked as such (i.e. don't recurse down)
if _, ok := field.Tag.Lookup(omitChildrenTag); ok {
path := strings.Join(append(path, field.Name), ".")
fieldPath := path
if jsonName != "" {
fieldPath = append(fieldPath, jsonName)
} else {
fieldPath = append(fieldPath, field.Name)
}
path := strings.Join(fieldPath, ".")
kind := field.Type.Kind()
if kind == reflect.Slice {
path += "[]"
Expand Down
30 changes: 29 additions & 1 deletion codegen/doc/helm_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,39 @@ import (
)

var _ = Describe("GenerateHelmValuesDoc", func() {
It("handles the case where the field has 'omitChildren' and json tag", func() {
type ChildType2 struct {
}
type ChildType struct {
Field1 *ChildType2 `json:"myCoolField" desc:"my field" omitChildren:"true"`
}
result := doc.GenerateHelmValuesDoc(
ChildType{},
"test",
"my test",
)
expected := doc.HelmValues{
{
Key: "test",
Type: "struct",
DefaultValue: " ",
Description: "my test",
},
{
Key: "test.myCoolField",
Type: "struct",
DefaultValue: " ",
Description: "my field",
},
}
Expect(result).To(Equal(expected))
})

It("handles case where map value struct has a nil pointer field that omits children", func() {
type ChildType2 struct {
}
type ChildType struct {
Field1 *ChildType2 `json:"field1" desc:"my field" omitChildren:"true"`
Field1 *ChildType2 `desc:"my field" omitChildren:"true"`
}

type TestType struct {
Expand Down

0 comments on commit 1e261f8

Please sign in to comment.