diff --git a/cloudformation/template.go b/cloudformation/template.go index a99dac9708..1156e1b2ff 100644 --- a/cloudformation/template.go +++ b/cloudformation/template.go @@ -134,6 +134,16 @@ func (t *Transform) UnmarshalJSON(b []byte) error { case []string: t.StringArray = &val + + case []interface{}: + var strslice []string + for _, i := range val { + switch str := i.(type) { + case string: + strslice = append(strslice, str) + } + } + t.StringArray = &strslice } return nil diff --git a/generate/templates/schema.template b/generate/templates/schema.template index b3c125ce6f..a520d43f98 100644 --- a/generate/templates/schema.template +++ b/generate/templates/schema.template @@ -27,7 +27,10 @@ "{{.ResourceSpecificationTransform}}" ] {{else}} - "type": ["object","string"] + "oneOf": [ + {"type": ["string"]}, + {"type": "array", "items": {"type": "string"}} + ] {{end}} }, diff --git a/goformation_test.go b/goformation_test.go index 80b8631c89..d40e94919c 100644 --- a/goformation_test.go +++ b/goformation_test.go @@ -758,6 +758,42 @@ var _ = Describe("Goformation", func() { }) + Context("with a YAML template with single transform macro", func() { + template, err := goformation.Open("test/yaml/transform-single.yaml") + + It("should parse the template successfully", func() { + Expect(template).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + + It("should parse transform macro into String field", func() { + Expect(*template.Transform.String).To(Equal("MyTranformMacro")) + }) + + It("should StringArray remain nil", func() { + Expect(template.Transform.StringArray).To(BeNil()) + }) + + }) + + Context("with a YAML template with multiple transform macros", func() { + template, err := goformation.Open("test/yaml/transform-multiple.yaml") + + It("should parse the template successfully", func() { + Expect(template).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + + It("should parse transform macro into StringArray field", func() { + Expect(*template.Transform.StringArray).To(Equal([]string{"FirstMacro", "SecondMacro"})) + }) + + It("should String remain nil", func() { + Expect(template.Transform.String).To(BeNil()) + }) + + }) + Context("with a YAML template with paramter overrides", func() { template, err := goformation.OpenWithOptions("test/yaml/aws-serverless-function-env-vars.yaml", &intrinsics.ProcessorOptions{ diff --git a/schema/cloudformation.go b/schema/cloudformation.go index 8fe332f891..6daf57492c 100644 --- a/schema/cloudformation.go +++ b/schema/cloudformation.go @@ -60700,9 +60700,18 @@ var CloudformationSchema = `{ "type": "object" }, "Transform": { - "type": [ - "object", - "string" + "oneOf": [ + { + "type": [ + "string" + ] + }, + { + "items": { + "type": "string" + }, + "type": "array" + } ] } }, diff --git a/schema/cloudformation.schema.json b/schema/cloudformation.schema.json index 5cbed52b49..1cea3a3b22 100644 --- a/schema/cloudformation.schema.json +++ b/schema/cloudformation.schema.json @@ -60697,9 +60697,18 @@ "type": "object" }, "Transform": { - "type": [ - "object", - "string" + "oneOf": [ + { + "type": [ + "string" + ] + }, + { + "items": { + "type": "string" + }, + "type": "array" + } ] } }, diff --git a/test/yaml/transform-multiple.yaml b/test/yaml/transform-multiple.yaml new file mode 100644 index 0000000000..479b8d627d --- /dev/null +++ b/test/yaml/transform-multiple.yaml @@ -0,0 +1,11 @@ +AWSTemplateFormatVersion: 2010-09-09 + +Resources: + ExampleTopic: + Type: AWS::SNS::Topic + Properties: + TopicName: example + +Transform: + - FirstMacro + - SecondMacro diff --git a/test/yaml/transform-single.yaml b/test/yaml/transform-single.yaml new file mode 100644 index 0000000000..33d280d3df --- /dev/null +++ b/test/yaml/transform-single.yaml @@ -0,0 +1,9 @@ +AWSTemplateFormatVersion: 2010-09-09 + +Resources: + ExampleTopic: + Type: AWS::SNS::Topic + Properties: + TopicName: example + +Transform: MyTranformMacro