Skip to content

Commit

Permalink
feat(generator): add support for new sagemaker properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfonseca committed Jun 14, 2022
1 parent 7048f11 commit bfd39c4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
31 changes: 30 additions & 1 deletion generate/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ func (p *Property) UnmarshalJSON(data []byte) error {
fmt.Printf("Warning: auto-fixing property that has a map of lists, with no list item type. Assuming the lists contain strings ([]string) for %s\n", p.Documentation)
}

if p.Type == "List" && p.ItemType == "List" && p.PrimitiveItemType == "" {
p.PrimitiveItemType = "String"
// WORKAROUND: On 2022-06-01, AWS::Rekognition::StreamProcessor published a property
// called 'PolygonRegionsOfInterest' which has Type: List, and ItemType: List, with no PrimitiveItemType.
// This workaround assumes that it should be a list, containing a list of strings.
fmt.Printf("Warning: auto-fixing property that has a list of lists, with no list item type. Assuming the lists contain strings ([]string) for %s\n", p.Documentation)
}

if p.Type == "Tag" && p.ItemType == "" {
p.ItemType = "Tag"
// WORKAROUND: On 2022-06-01, AWS::Rekognition::ModelPackage published a property
// called 'Tag' with no ItemType.
// This workaround assumes that it should be a tag.
fmt.Printf("Warning: auto-fixing property that is marked as tag but has no tag ItemType for %s\n", p.Documentation)
}

return nil

}
Expand Down Expand Up @@ -249,6 +265,13 @@ func (p Property) IsCustomType() bool {
// within a Go struct. For example, []string or map[string]AWSLambdaFunction_VpcConfig
func (p Property) GoType(typename string, basename string, name string) string {

if p.Type == "Tag" && p.ItemType == "Tag" {
// WORKAROUND: On 2022-06-01, AWS::Rekognition::ModelPackage published a property
// called 'Tag' with no ItemType.
// This workaround assumes that it should be a tag.
return "tags.Tag"
}

if p.ItemType == "Tag" {
return "[]tags.Tag"
}
Expand All @@ -261,6 +284,13 @@ func (p Property) GoType(typename string, basename string, name string) string {
return "map[string][]string"
}

if p.Type == "List" && p.ItemType == "List" && p.PrimitiveItemType == "String" {
// WORKAROUND: On 2022-06-01, AWS::Rekognition::StreamProcessor published a property
// called 'PolygonRegionsOfInterest' which has Type: List, and ItemType: List, with no PrimitiveItemType.
// This workaround assumes that it should be a list, containing a list of strings.
return "[][]string"
}

if p.IsPolymorphic() {

generatePolymorphicProperty(typename, basename+"_"+name, p)
Expand All @@ -285,7 +315,6 @@ func (p Property) GoType(typename string, basename string, name string) string {
}

return "[]" + basename + "_" + p.ItemType

}

if p.IsCustomType() {
Expand Down
4 changes: 4 additions & 0 deletions generate/templates/schema-property.template
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,9 @@
{{end}}
{{end}}

{{ if and (eq .Property.Type "Tag") (eq .Property.ItemType "Tag") }}
"$ref": "#/definitions/Tag"
{{end}}

{{end}}
}
2 changes: 1 addition & 1 deletion goformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ var _ = Describe("Goformation", func() {
template := cloudformation.NewTemplate()

template.Resources["Vpc"] = &ec2.VPC{
CidrBlock: "192.168.0.0/20",
CidrBlock: cloudformation.String("192.168.0.0/20"),
}

template.Outputs["VpcId"] = cloudformation.Output{
Expand Down

0 comments on commit bfd39c4

Please sign in to comment.