diff --git a/pkg/envoy/yaml/compose_page_marshal.go b/pkg/envoy/yaml/compose_page_marshal.go index 2e79d0d32..d766d9676 100644 --- a/pkg/envoy/yaml/compose_page_marshal.go +++ b/pkg/envoy/yaml/compose_page_marshal.go @@ -262,19 +262,14 @@ func (c *composePageBlock) cleanupModuleFields(opt map[string]interface{}) { retFF := make([]interface{}, 0, len(ff)) for _, rawF := range ff { - f, ok := rawF.(map[string]interface{}) - if !ok { + switch c := rawF.(type) { + case string: + retFF = append(retFF, map[string]interface{}{"name": c}) + case map[string]interface{}, map[string]string: + retFF = append(retFF, c) + default: retFF = append(retFF, rawF) - continue } - - fn, has := f["name"] - if !has { - retFF = append(retFF, rawF) - continue - } - - retFF = append(retFF, fn) } opt["fields"] = retFF diff --git a/tests/envoy/store_yaml_pages_test.go b/tests/envoy/store_yaml_pages_test.go index 4687cb1b6..eb642b8d8 100644 --- a/tests/envoy/store_yaml_pages_test.go +++ b/tests/envoy/store_yaml_pages_test.go @@ -2,6 +2,7 @@ package envoy import ( "context" + "fmt" "strconv" "testing" @@ -322,6 +323,10 @@ func TestStoreYaml_pageRefs(t *testing.T) { Kind: "RecordList", Options: map[string]interface{}{ "module": strconv.FormatUint(mod.ID, 10), + "fields": []map[string]interface{}{ + {"name": "f1"}, + {"name": "f2"}, + }, }, }, { @@ -329,6 +334,10 @@ func TestStoreYaml_pageRefs(t *testing.T) { Kind: "RecordList", Options: map[string]interface{}{ "moduleID": strconv.FormatUint(mod.ID, 10), + "fields": []map[string]interface{}{ + {"name": "f1"}, + {"name": "f2"}, + }, }, }, }, @@ -363,10 +372,20 @@ func TestStoreYaml_pageRefs(t *testing.T) { // provided as module b := pg.Blocks[0] req.Equal(strconv.FormatUint(mod.ID, 10), b.Options["moduleID"]) + casted := b.Options["fields"].([]interface{}) + for i, c := range casted { + cc := c.(map[string]interface{}) + req.Equal(fmt.Sprintf("f%d", i+1), cc["name"].(string)) + } // provided as moduleID b = pg.Blocks[1] req.Equal(strconv.FormatUint(mod.ID, 10), b.Options["moduleID"]) + casted = b.Options["fields"].([]interface{}) + for i, c := range casted { + cc := c.(map[string]interface{}) + req.Equal(fmt.Sprintf("f%d", i+1), cc["name"].(string)) + } }, },