Skip to content

Commit c7357bd

Browse files
committed
Allow OperatorType to be a list such that one API can map to multiple operations
1 parent 821a0da commit c7357bd

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

pkg/generate/config/operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type OperationConfig struct {
3737
ResourceName string `json:"resource_name"`
3838
// Override for operation type in case of heuristic failure
3939
// An example of this is `Put...` or `Register...` API operations not being correctly classified as `Create` op type
40-
OperationType string `json:"operation_type"`
40+
OperationType []string `json:"operation_type"`
4141
// PrimaryIdentifierFieldName provides the name of the field that should be
4242
// interpreted as the "primary" identifier field. This field will be used as
4343
// the primary field for resource adoption.

pkg/model/sdk_helper.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap {
206206
// create an index of Operations by operation types and resource name
207207
opMap := OperationMap{}
208208
for opID, op := range a.API.Operations {
209-
opType, resName := getOpTypeAndResourceName(opID, cfg)
210-
if _, found := opMap[opType]; !found {
211-
opMap[opType] = map[string]*awssdkmodel.Operation{}
212-
}
213-
opMap[opType][resName] = op
209+
opTypeArray, resName := getOpTypeAndResourceName(opID, cfg)
210+
for _, opType := range opTypeArray {
211+
if _, found := opMap[opType]; !found {
212+
opMap[opType] = map[string]*awssdkmodel.Operation{}
213+
}
214+
opMap[opType][resName] = op
215+
}
214216
}
215217
a.opMap = &opMap
216218
return &opMap
@@ -382,20 +384,27 @@ func (a *SDKAPI) SDKAPIInterfaceTypeName() string {
382384
}
383385

384386
// Override the operation type and/or resource name if specified in config
385-
func getOpTypeAndResourceName(opID string, cfg *ackgenconfig.Config) (OpType, string) {
387+
func getOpTypeAndResourceName(opID string, cfg *ackgenconfig.Config) ([]OpType, string) {
386388
opType, resName := GetOpTypeAndResourceNameFromOpID(opID)
387-
389+
opTypeArray := make([]OpType, 0)
390+
// TODO: or use var opTypeArray []OpType
388391
if cfg != nil {
389392
if operationConfig, exists := cfg.Operations[opID]; exists {
390-
if operationConfig.OperationType != "" {
391-
opType = OpTypeFromString(operationConfig.OperationType)
392-
}
393-
394393
if operationConfig.ResourceName != "" {
395394
resName = operationConfig.ResourceName
396395
}
397-
}
398-
}
399396

400-
return opType, resName
397+
if len(operationConfig.OperationType) > 0 {
398+
for _, operationType := range operationConfig.OperationType {
399+
opType = OpTypeFromString(operationType)
400+
opTypeArray = append(opTypeArray, opType)
401+
}
402+
} else {
403+
opTypeArray = append(opTypeArray, opType)
404+
}
405+
} else {
406+
opTypeArray = append(opTypeArray, opType)
407+
}
408+
}
409+
return opTypeArray, resName
401410
}

0 commit comments

Comments
 (0)