@@ -295,7 +295,7 @@ func (m *Model) GetCRDs() ([]*CRD, error) {
295295 // This is the place that we build out the CRD.Fields map with
296296 // `pkg/model.Field` objects that represent the non-top-level Spec and
297297 // Status fields.
298- m .processNestedFields (crds )
298+ m .processFields (crds )
299299 m .crds = crds
300300 return crds , nil
301301}
@@ -472,9 +472,10 @@ func replaceSecretAttrGoType(
472472 field * Field ,
473473 tdefs []* TypeDef ,
474474) {
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 ()]
478479 if ! ok {
479480 msg := fmt .Sprintf (
480481 "Cannot find parent field at parent path %s for %s" ,
@@ -546,25 +547,25 @@ func replaceSecretAttrGoType(
546547 attr .GoType = "*ackv1alpha1.SecretKeyReference"
547548}
548549
549- // processNestedFields is responsible for walking all of the CRDs' Spec and
550+ // processFields is responsible for walking all of the CRDs' Spec and
550551// Status fields' Shape objects and adding `pkg/model.Field` objects for all
551552// nested fields along with that `Field`'s `Config` object that allows us to
552553// determine if the TypeDef associated with that nested field should have its
553554// data type overridden (e.g. for SecretKeyReferences)
554- func (m * Model ) processNestedFields (crds []* CRD ) {
555+ func (m * Model ) processFields (crds []* CRD ) {
555556 for _ , crd := range crds {
556557 for _ , field := range crd .SpecFields {
557- m .processNestedField (crd , field )
558+ m .processTopLevelField (crd , field )
558559 }
559560 for _ , field := range crd .StatusFields {
560- m .processNestedField (crd , field )
561+ m .processTopLevelField (crd , field )
561562 }
562563 }
563564}
564565
565- // processNestedField processes any nested fields (non-scalar fields associated
566+ // processTopLevelField processes any nested fields (non-scalar fields associated
566567// with the Spec and Status objects)
567- func (m * Model ) processNestedField (
568+ func (m * Model ) processTopLevelField (
568569 crd * CRD ,
569570 field * Field ,
570571) {
@@ -581,106 +582,87 @@ func (m *Model) processNestedField(
581582 fieldType := fieldShape .Type
582583 switch fieldType {
583584 case "structure" :
584- m .processNestedStructField (crd , field .Path + "." , field )
585+ m .processStructField (crd , field .Path + "." , field )
585586 case "list" :
586- m .processNestedListField (crd , field .Path + ". ." , field )
587+ m .processListField (crd , field .Path + "." , field )
587588 case "map" :
588- m .processNestedMapField (crd , field .Path + ". ." , field )
589+ m .processMapField (crd , field .Path + "." , field )
589590 }
590591 }
591592}
592593
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 (
596596 crd * CRD ,
597- baseFieldPath string ,
598- baseField * Field ,
597+ parentFieldPath string ,
598+ parentField * Field ,
599+ fieldName string ,
600+ fieldShapeRef * awssdkmodel.ShapeRef ,
599601) {
600602 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 )
618630 }
619631}
620632
621- // processNestedListField recurses through the members of a nested field that
633+ // processListField recurses through the members of a nested field that
622634// is a list type that has a struct element type and adds any Field objects to
623635// the supplied CRD.
624- func (m * Model ) processNestedListField (
636+ func (m * Model ) processListField (
625637 crd * CRD ,
626- baseFieldPath string ,
627- baseField * Field ,
638+ fieldPath string ,
639+ field * Field ,
628640) {
629- baseFieldShape := baseField .ShapeRef .Shape
630- elementFieldShape := baseFieldShape .MemberRef .Shape
641+ fieldShape := field .ShapeRef .Shape
642+ elementFieldShape := fieldShape .MemberRef .Shape
631643 if elementFieldShape .Type != "structure" {
632644 return
633645 }
634- fieldConfigs := crd .Config ().ResourceFields (crd .Names .Original )
635646 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 )
651648 }
652649}
653650
654- // processNestedMapField recurses through the members of a nested field that
651+ // processMapField recurses through the members of a nested field that
655652// is a map type that has a struct value type and adds any Field objects to
656653// the supplied CRD.
657- func (m * Model ) processNestedMapField (
654+ func (m * Model ) processMapField (
658655 crd * CRD ,
659- baseFieldPath string ,
660- baseField * Field ,
656+ fieldPath string ,
657+ field * Field ,
661658) {
662- baseFieldShape := baseField .ShapeRef .Shape
663- valueFieldShape := baseFieldShape .ValueRef .Shape
659+ fieldShape := field .ShapeRef .Shape
660+ valueFieldShape := fieldShape .ValueRef .Shape
664661 if valueFieldShape .Type != "structure" {
665662 return
666663 }
667- fieldConfigs := crd .Config ().ResourceFields (crd .Names .Original )
668664 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 )
684666 }
685667}
686668
0 commit comments