From 0eb20a07fde7a83ef7cf0d07192379b9d0614300 Mon Sep 17 00:00:00 2001 From: Paul Maddox Date: Tue, 25 Aug 2020 08:53:36 +0400 Subject: [PATCH] Check for properties with no type in CFN spec 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 #300 --- generate/generate.go | 10 ++++++++++ generate/property.go | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/generate/generate.go b/generate/generate.go index 3bc74b7636..e0b81bedcd 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -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 { diff --git a/generate/property.go b/generate/property.go index 55fdbd386b..3667b21fb2 100644 --- a/generate/property.go +++ b/generate/property.go @@ -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