Skip to content

Commit

Permalink
Check for properties with no type in CFN spec
Browse files Browse the repository at this point in the history
If the CloudFormation Resource Specification has a resource property
that does not include any type information then this should be a
breaking error and generation should fail.

See awslabs#300
  • Loading branch information
PaulMaddox committed Aug 25, 2020
1 parent 2dbbc97 commit 0eb20a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ func (rg *ResourceGenerator) processSpec(specname string, data []byte) (*CloudFo
return nil, err
}

// Check that all of resource properties have a valid type
// see: https://github.com/awslabs/goformation/issues/300
for rname, resource := range spec.Resources {
for pname, property := range resource.Properties {
if !property.HasValidType() {
return nil, fmt.Errorf("%s.%s has no type information in the CloudFormation Resource Specification", rname, pname)
}
}
}

// Add the resources processed to the ResourceGenerator output
for name := range spec.Resources {

Expand Down
16 changes: 16 additions & 0 deletions generate/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ func (p Property) Schema(name, parent string) string {

}

// HasValidType checks whether a property has a valid type defined
// It is possible that an invalid CloudFormation Resource Specification is published
// that does not have any type information for a property. If this happens, then
// generation should fail with an error message.
func (p Property) HasValidType() bool {
invalid := p.ItemType == "" &&
p.PrimitiveType == "" &&
p.PrimitiveItemType == "" &&
p.Type == "" &&
len(p.ItemTypes) == 0 &&
len(p.PrimitiveTypes) == 0 &&
len(p.PrimitiveItemTypes) == 0 &&
len(p.Types) == 0
return !invalid
}

// IsPolymorphic checks whether a property can be multiple different types
func (p Property) IsPolymorphic() bool {
return len(p.PrimitiveTypes) > 0 || len(p.PrimitiveItemTypes) > 0 || len(p.PrimitiveItemTypes) > 0 || len(p.ItemTypes) > 0 || len(p.Types) > 0
Expand Down

0 comments on commit 0eb20a0

Please sign in to comment.