in cft/build/build.go [75:141]
func (b builder) newProperty(resourceType, propertyName string, pSpec *spec.Property) (interface{}, []*cft.Comment) {
defer func() {
if r := recover(); r != nil {
panic(fmt.Errorf("error building property %s.%s: %w", resourceType, propertyName, r))
}
}()
// Correct badly-formed entries
if pSpec.PrimitiveType == spec.TypeMap {
pSpec.PrimitiveType = spec.TypeEmpty
pSpec.Type = spec.TypeMap
}
// Primitive types
if pSpec.PrimitiveType != spec.TypeEmpty {
if pSpec.Required {
return b.newPrimitive(pSpec.PrimitiveType), make([]*cft.Comment, 0)
}
return b.newPrimitive(pSpec.PrimitiveType), []*cft.Comment{{
Path: []interface{}{},
Value: optionalTag,
}}
}
if pSpec.Type == spec.TypeList || pSpec.Type == spec.TypeMap {
var value interface{}
var subComments []*cft.Comment
// Calculate a single item example
if pSpec.PrimitiveItemType != spec.TypeEmpty {
value = b.newPrimitive(pSpec.PrimitiveItemType)
} else if pSpec.ItemType != spec.TypeEmpty {
value, subComments = b.newPropertyType(resourceType, pSpec.ItemType)
} else {
value = changeMeTag
}
if pSpec.Type == spec.TypeList {
// Returning a list - append a zero to comment paths
for _, c := range subComments {
c.Path = append([]interface{}{0}, c.Path...)
}
return []interface{}{value}, subComments
}
// Returning a map - append changemetag to comment paths
for _, c := range subComments {
c.Path = append([]interface{}{changeMeTag}, c.Path...)
}
return map[string]interface{}{changeMeTag: value}, subComments
}
// Fall through to property types
output, comments := b.newPropertyType(resourceType, pSpec.Type)
if !pSpec.Required {
comments = append(comments, &cft.Comment{
Path: []interface{}{},
Value: optionalTag,
})
}
return output, comments
}