@@ -295,7 +295,7 @@ func (m *Model) GetCRDs() ([]*CRD, error) {
295
295
// This is the place that we build out the CRD.Fields map with
296
296
// `pkg/model.Field` objects that represent the non-top-level Spec and
297
297
// Status fields.
298
- m .processNestedFields (crds )
298
+ m .processFields (crds )
299
299
m .crds = crds
300
300
return crds , nil
301
301
}
@@ -472,9 +472,10 @@ func replaceSecretAttrGoType(
472
472
field * Field ,
473
473
tdefs []* TypeDef ,
474
474
) {
475
- fieldPath := field .Path
476
- parentFieldPath := ParentFieldPath (field .Path )
477
- parentField , ok := crd .Fields [parentFieldPath ]
475
+ fieldPath := ackfp .FromString (field .Path )
476
+ parentFieldPath := fieldPath .Copy ()
477
+ parentFieldPath .Pop ()
478
+ parentField , ok := crd .Fields [parentFieldPath .String ()]
478
479
if ! ok {
479
480
msg := fmt .Sprintf (
480
481
"Cannot find parent field at parent path %s for %s" ,
@@ -546,25 +547,25 @@ func replaceSecretAttrGoType(
546
547
attr .GoType = "*ackv1alpha1.SecretKeyReference"
547
548
}
548
549
549
- // processNestedFields is responsible for walking all of the CRDs' Spec and
550
+ // processFields is responsible for walking all of the CRDs' Spec and
550
551
// Status fields' Shape objects and adding `pkg/model.Field` objects for all
551
552
// nested fields along with that `Field`'s `Config` object that allows us to
552
553
// determine if the TypeDef associated with that nested field should have its
553
554
// data type overridden (e.g. for SecretKeyReferences)
554
- func (m * Model ) processNestedFields (crds []* CRD ) {
555
+ func (m * Model ) processFields (crds []* CRD ) {
555
556
for _ , crd := range crds {
556
557
for _ , field := range crd .SpecFields {
557
- m .processNestedField (crd , field )
558
+ m .processTopLevelField (crd , field )
558
559
}
559
560
for _ , field := range crd .StatusFields {
560
- m .processNestedField (crd , field )
561
+ m .processTopLevelField (crd , field )
561
562
}
562
563
}
563
564
}
564
565
565
- // processNestedField processes any nested fields (non-scalar fields associated
566
+ // processTopLevelField processes any nested fields (non-scalar fields associated
566
567
// with the Spec and Status objects)
567
- func (m * Model ) processNestedField (
568
+ func (m * Model ) processTopLevelField (
568
569
crd * CRD ,
569
570
field * Field ,
570
571
) {
@@ -581,106 +582,87 @@ func (m *Model) processNestedField(
581
582
fieldType := fieldShape .Type
582
583
switch fieldType {
583
584
case "structure" :
584
- m .processNestedStructField (crd , field .Path + "." , field )
585
+ m .processStructField (crd , field .Path + "." , field )
585
586
case "list" :
586
- m .processNestedListField (crd , field .Path + ". ." , field )
587
+ m .processListField (crd , field .Path + "." , field )
587
588
case "map" :
588
- m .processNestedMapField (crd , field .Path + ". ." , field )
589
+ m .processMapField (crd , field .Path + "." , field )
589
590
}
590
591
}
591
592
}
592
593
593
- // processNestedStructField recurses through the members of a nested field that
594
- // is a struct type and adds any Field objects to the supplied CRD.
595
- func (m * Model ) processNestedStructField (
594
+ // processField adds a new Field definition for a field within the CR
595
+ func (m * Model ) processField (
596
596
crd * CRD ,
597
- baseFieldPath string ,
598
- baseField * Field ,
597
+ parentFieldPath string ,
598
+ parentField * Field ,
599
+ fieldName string ,
600
+ fieldShapeRef * awssdkmodel.ShapeRef ,
599
601
) {
600
602
fieldConfigs := crd .Config ().ResourceFields (crd .Names .Original )
601
- baseFieldShape := baseField .ShapeRef .Shape
602
- for memberName , memberRef := range baseFieldShape .MemberRefs {
603
- memberNames := names .New (memberName )
604
- memberShape := memberRef .Shape
605
- memberShapeType := memberShape .Type
606
- fieldPath := baseFieldPath + memberNames .Camel
607
- fieldConfig := fieldConfigs [fieldPath ]
608
- field := NewField (crd , fieldPath , memberNames , memberRef , fieldConfig )
609
- switch memberShapeType {
610
- case "structure" :
611
- m .processNestedStructField (crd , fieldPath + "." , field )
612
- case "list" :
613
- m .processNestedListField (crd , fieldPath + ".." , field )
614
- case "map" :
615
- m .processNestedMapField (crd , fieldPath + ".." , field )
616
- }
617
- crd .Fields [fieldPath ] = field
603
+ fieldNames := names .New (fieldName )
604
+ fieldShape := fieldShapeRef .Shape
605
+ fieldShapeType := fieldShape .Type
606
+ fieldPath := parentFieldPath + fieldNames .Camel
607
+ fieldConfig := fieldConfigs [fieldPath ]
608
+ field := NewField (crd , fieldPath , fieldNames , fieldShapeRef , fieldConfig )
609
+ switch fieldShapeType {
610
+ case "structure" :
611
+ m .processStructField (crd , fieldPath + "." , field )
612
+ case "list" :
613
+ m .processListField (crd , fieldPath + "." , field )
614
+ case "map" :
615
+ m .processMapField (crd , fieldPath + "." , field )
616
+ }
617
+ crd .Fields [fieldPath ] = field
618
+ }
619
+
620
+ // processStructField recurses through the members of a nested field that
621
+ // is a struct type and adds any Field objects to the supplied CRD.
622
+ func (m * Model ) processStructField (
623
+ crd * CRD ,
624
+ fieldPath string ,
625
+ field * Field ,
626
+ ) {
627
+ fieldShape := field .ShapeRef .Shape
628
+ for memberName , memberRef := range fieldShape .MemberRefs {
629
+ m .processField (crd , fieldPath , field , memberName , memberRef )
618
630
}
619
631
}
620
632
621
- // processNestedListField recurses through the members of a nested field that
633
+ // processListField recurses through the members of a nested field that
622
634
// is a list type that has a struct element type and adds any Field objects to
623
635
// the supplied CRD.
624
- func (m * Model ) processNestedListField (
636
+ func (m * Model ) processListField (
625
637
crd * CRD ,
626
- baseFieldPath string ,
627
- baseField * Field ,
638
+ fieldPath string ,
639
+ field * Field ,
628
640
) {
629
- baseFieldShape := baseField .ShapeRef .Shape
630
- elementFieldShape := baseFieldShape .MemberRef .Shape
641
+ fieldShape := field .ShapeRef .Shape
642
+ elementFieldShape := fieldShape .MemberRef .Shape
631
643
if elementFieldShape .Type != "structure" {
632
644
return
633
645
}
634
- fieldConfigs := crd .Config ().ResourceFields (crd .Names .Original )
635
646
for memberName , memberRef := range elementFieldShape .MemberRefs {
636
- memberNames := names .New (memberName )
637
- memberShape := memberRef .Shape
638
- memberShapeType := memberShape .Type
639
- fieldPath := baseFieldPath + memberNames .Camel
640
- fieldConfig := fieldConfigs [fieldPath ]
641
- field := NewField (crd , fieldPath , memberNames , memberRef , fieldConfig )
642
- switch memberShapeType {
643
- case "structure" :
644
- m .processNestedStructField (crd , fieldPath + "." , field )
645
- case "list" :
646
- m .processNestedListField (crd , fieldPath + ".." , field )
647
- case "map" :
648
- m .processNestedMapField (crd , fieldPath + ".." , field )
649
- }
650
- crd .Fields [fieldPath ] = field
647
+ m .processField (crd , fieldPath , field , memberName , memberRef )
651
648
}
652
649
}
653
650
654
- // processNestedMapField recurses through the members of a nested field that
651
+ // processMapField recurses through the members of a nested field that
655
652
// is a map type that has a struct value type and adds any Field objects to
656
653
// the supplied CRD.
657
- func (m * Model ) processNestedMapField (
654
+ func (m * Model ) processMapField (
658
655
crd * CRD ,
659
- baseFieldPath string ,
660
- baseField * Field ,
656
+ fieldPath string ,
657
+ field * Field ,
661
658
) {
662
- baseFieldShape := baseField .ShapeRef .Shape
663
- valueFieldShape := baseFieldShape .ValueRef .Shape
659
+ fieldShape := field .ShapeRef .Shape
660
+ valueFieldShape := fieldShape .ValueRef .Shape
664
661
if valueFieldShape .Type != "structure" {
665
662
return
666
663
}
667
- fieldConfigs := crd .Config ().ResourceFields (crd .Names .Original )
668
664
for memberName , memberRef := range valueFieldShape .MemberRefs {
669
- memberNames := names .New (memberName )
670
- memberShape := memberRef .Shape
671
- memberShapeType := memberShape .Type
672
- fieldPath := baseFieldPath + memberNames .Camel
673
- fieldConfig := fieldConfigs [fieldPath ]
674
- field := NewField (crd , fieldPath , memberNames , memberRef , fieldConfig )
675
- switch memberShapeType {
676
- case "structure" :
677
- m .processNestedStructField (crd , fieldPath + "." , field )
678
- case "list" :
679
- m .processNestedListField (crd , fieldPath + ".." , field )
680
- case "map" :
681
- m .processNestedMapField (crd , fieldPath + ".." , field )
682
- }
683
- crd .Fields [fieldPath ] = field
665
+ m .processField (crd , fieldPath , field , memberName , memberRef )
684
666
}
685
667
}
686
668
0 commit comments