Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Align Transform field format with actual Cloudformation support #268

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cloudformation/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion generate/templates/schema.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
"{{.ResourceSpecificationTransform}}"
]
{{else}}
"type": ["object","string"]
"oneOf": [
{"type": ["string"]},
{"type": "array", "items": {"type": "string"}}
]
{{end}}
},

Expand Down
36 changes: 36 additions & 0 deletions goformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
15 changes: 12 additions & 3 deletions schema/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60700,9 +60700,18 @@ var CloudformationSchema = `{
"type": "object"
},
"Transform": {
"type": [
"object",
"string"
"oneOf": [
{
"type": [
"string"
]
},
{
"items": {
"type": "string"
},
"type": "array"
}
]
}
},
Expand Down
15 changes: 12 additions & 3 deletions schema/cloudformation.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60697,9 +60697,18 @@
"type": "object"
},
"Transform": {
"type": [
"object",
"string"
"oneOf": [
{
"type": [
"string"
]
},
{
"items": {
"type": "string"
},
"type": "array"
}
]
}
},
Expand Down
11 changes: 11 additions & 0 deletions test/yaml/transform-multiple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
AWSTemplateFormatVersion: 2010-09-09

Resources:
ExampleTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: example

Transform:
- FirstMacro
- SecondMacro
9 changes: 9 additions & 0 deletions test/yaml/transform-single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AWSTemplateFormatVersion: 2010-09-09

Resources:
ExampleTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: example

Transform: MyTranformMacro