Skip to content

Commit d09dce1

Browse files
committed
Adding functionality to assign one API to multiple resources
1 parent 892f29d commit d09dce1

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

pkg/config/operation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type OperationConfig struct {
4040
OutputWrapperFieldPath string `json:"output_wrapper_field_path,omitempty"`
4141
// Override for resource name in case of heuristic failure
4242
// An example of this is correcting stutter when the resource logic doesn't properly determine the resource name
43-
ResourceName string `json:"resource_name"`
43+
ResourceName StringArray `json:"resource_name"`
4444
// Override for operation type in case of heuristic failure
4545
// An example of this is `Put...` or `Register...` API operations not being correctly classified as `Create` op type
4646
// OperationType []string `json:"operation_type"`
@@ -59,8 +59,8 @@ func (c *Config) OperationIsIgnored(operation *awssdkmodel.Operation) bool {
5959
return util.InStrings(operation.ExportedName, c.Ignore.Operations)
6060
}
6161

62-
// UnmarshalJSON parses input for a either a string or
63-
// or a list and returns a StringArray.
62+
// UnmarshalJSON parses input for either a string or
63+
// a list and returns a StringArray.
6464
func (a *StringArray) UnmarshalJSON(b []byte) error {
6565
var multi []string
6666
err := json.Unmarshal(b, &multi)

pkg/model/sdk_api.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap {
7878
// create an index of Operations by operation types and resource name
7979
opMap := OperationMap{}
8080
for opID, op := range a.API.Operations {
81-
opTypeArray, resName := getOpTypeAndResourceName(opID, cfg)
81+
opTypeArray, resList := getOpTypeAndResourceName(opID, cfg)
8282
for _, opType := range opTypeArray {
8383
if _, found := opMap[opType]; !found {
8484
opMap[opType] = map[string]*awssdkmodel.Operation{}
8585
}
86-
opMap[opType][resName] = op
86+
for _, resName := range resList {
87+
opMap[opType][resName] = op
88+
}
8789
}
8890
}
8991

@@ -98,16 +100,18 @@ func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap {
98100
//
99101
// see: https://github.com/aws-controllers-k8s/community/issues/1555
100102
for opID, opCfg := range cfg.Operations {
101-
if opCfg.ResourceName == "" {
103+
if opCfg.ResourceName == nil {
102104
continue
103105
}
104106
op, found := a.API.Operations[opID]
105107
if !found {
106108
panic("operation " + opID + " in generator.yaml 'operations:' object does not exist.")
107109
}
108110
for _, operationType := range opCfg.OperationType {
109-
opType := OpTypeFromString(operationType)
110-
opMap[opType][opCfg.ResourceName] = op
111+
for _, resName := range opCfg.ResourceName {
112+
opType := OpTypeFromString(operationType)
113+
opMap[opType][resName] = op
114+
}
111115
}
112116
}
113117
a.opMap = &opMap
@@ -360,20 +364,19 @@ func NewSDKAPI(api *awssdkmodel.API, apiGroupSuffix string) *SDKAPI {
360364
}
361365

362366
// Override the operation type and/or resource name, if specified in config
363-
func getOpTypeAndResourceName(opID string, cfg *ackgenconfig.Config) ([]OpType, string) {
367+
func getOpTypeAndResourceName(opID string, cfg *ackgenconfig.Config) ([]OpType, []string) {
364368
opType, resName := GetOpTypeAndResourceNameFromOpID(opID, cfg)
365369
opTypes := []OpType{opType}
370+
resList := []string{resName}
366371

367372
if operationConfig, exists := cfg.GetOperationConfig(opID); exists {
368-
if operationConfig.ResourceName != "" {
369-
resName = operationConfig.ResourceName
370-
}
373+
resList = operationConfig.ResourceName
371374
for _, operationType := range operationConfig.OperationType {
372375
opType = OpTypeFromString(operationType)
373376
opTypes = append(opTypes, opType)
374377
}
375378
}
376-
return opTypes, resName
379+
return opTypes, resList
377380
}
378381

379382
// getMemberByPath returns a ShapeRef given a root Shape and a dot-notation

0 commit comments

Comments
 (0)