Skip to content

Commit a229841

Browse files
committed
Add a new CRD method to query all the renames observed in generator.yaml
This patch introduces a new function that returns all the observed renames for a given CRD and for a specific `generator.yaml` file. It returns two different maps, the first mapping old names with new ones and the other mapping old ones with new ones.
1 parent 43b45a0 commit a229841

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/model/crd.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,36 @@ func (r *CRD) ListOpMatchFieldNames() []string {
618618
return r.cfg.ListOpMatchFieldNames(r.Names.Original)
619619
}
620620

621+
// GetAllRenames returns all the field renames observed in the generator config
622+
// for a given OpType.
623+
func (r *CRD) GetAllRenames(op OpType) (map[string]string, error) {
624+
renames := make(map[string]string)
625+
resourceConfig, ok := r.cfg.Resources[r.Names.Original]
626+
if !ok {
627+
return renames, nil
628+
}
629+
630+
opMap := r.sdkAPI.GetOperationMap(r.cfg)
631+
operations := (*opMap)[op]
632+
633+
if resourceConfig.Renames == nil || resourceConfig.Renames.Operations == nil {
634+
return renames, nil
635+
}
636+
637+
opRenameConfigs := resourceConfig.Renames.Operations
638+
for opName, opRenameConfigs := range opRenameConfigs {
639+
for _, op := range operations {
640+
if opName != op.Name {
641+
continue
642+
}
643+
for old, new := range opRenameConfigs.InputFields {
644+
renames[old] = new
645+
}
646+
}
647+
}
648+
return renames, nil
649+
}
650+
621651
// NewCRD returns a pointer to a new `ackmodel.CRD` struct that describes a
622652
// single top-level resource in an AWS service API
623653
func NewCRD(

0 commit comments

Comments
 (0)