Skip to content

Commit 5a40e37

Browse files
author
Nicholas Thomson
committed
Allow spec fields from other operations
1 parent cae7cb2 commit 5a40e37

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pkg/model/crd.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func (r *CRD) HasShapeAsMember(toFind string) bool {
143143
}
144144
}
145145
}
146+
for _, field := range r.SpecFields {
147+
if shapeHasMember(field.ShapeRef.Shape, toFind) {
148+
return true
149+
}
150+
}
146151
return false
147152
}
148153

@@ -236,6 +241,17 @@ func (r *CRD) SpecFieldNames() []string {
236241
return res
237242
}
238243

244+
// SpecFieldShapeNames returns a sorted slice of shape names for each of the
245+
// Spec fields
246+
func (r *CRD) SpecFieldShapeNames() []string {
247+
res := make([]string, 0, len(r.SpecFields))
248+
for _, field := range r.SpecFields {
249+
res = append(res, field.ShapeRef.ShapeName)
250+
}
251+
sort.Strings(res)
252+
return res
253+
}
254+
239255
// UnpacksAttributesMap returns true if the underlying API has
240256
// Get{Resource}Attributes/Set{Resource}Attributes API calls that map real,
241257
// schema'd fields to a raw `map[string]*string` for this resource (see SNS and

pkg/model/model.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ func (m *Model) IsShapeUsedInCRDs(shapeName string) bool {
279279
return false
280280
}
281281

282+
// IsShapeInSpec returns true if the supplied shape name is directly used as a
283+
// field in the CRD's spec
284+
func (m *Model) IsShapeInSpec(shapeName string) bool {
285+
crds, _ := m.GetCRDs()
286+
for _, crd := range crds {
287+
if util.InStrings(shapeName, crd.SpecFieldShapeNames()) {
288+
return true
289+
}
290+
}
291+
return false
292+
}
293+
282294
// GetTypeDefs returns a slice of `TypeDef` pointers
283295
func (m *Model) GetTypeDefs() ([]*TypeDef, error) {
284296
if m.typeDefs != nil {
@@ -310,17 +322,20 @@ func (m *Model) GetTypeDefs() ([]*TypeDef, error) {
310322
trenames[shapeName] = tdefNames.Camel
311323
}
312324

325+
// Shape is used directly in the spec
326+
baseUsed := m.IsShapeInSpec(shapeName)
327+
313328
attrs := map[string]*Attr{}
314329
for memberName, memberRef := range shape.MemberRefs {
315330
memberNames := names.New(memberName)
316331
memberShape := memberRef.Shape
317-
if !m.IsShapeUsedInCRDs(memberShape.ShapeName) {
332+
if !baseUsed && !m.IsShapeUsedInCRDs(memberShape.ShapeName) {
318333
continue
319334
}
320335
gt := m.getShapeCleanGoType(memberShape)
321336
attrs[memberName] = NewAttr(memberNames, gt, memberShape)
322337
}
323-
if len(attrs) == 0 {
338+
if !baseUsed && len(attrs) == 0 {
324339
// Just ignore these...
325340
continue
326341
}

0 commit comments

Comments
 (0)