@@ -18,6 +18,8 @@ import (
18
18
19
19
awssdkmodel "github.com/aws/aws-sdk-go/private/model/api"
20
20
"github.com/gertd/go-pluralize"
21
+
22
+ ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
21
23
)
22
24
23
25
type OpType int
@@ -43,26 +45,42 @@ type OperationMap map[OpType]map[string]*awssdkmodel.Operation
43
45
44
46
// GetOpTypeAndResourceNameFromOpID guesses the resource name and type of
45
47
// operation from the OperationID
46
- func GetOpTypeAndResourceNameFromOpID (opID string ) (OpType , string ) {
48
+ func GetOpTypeAndResourceNameFromOpID (
49
+ opID string ,
50
+ cfg * ackgenconfig.Config ,
51
+ ) (OpType , string ) {
47
52
pluralize := pluralize .NewClient ()
48
53
if strings .HasPrefix (opID , "CreateOrUpdate" ) {
49
54
return OpTypeReplace , strings .TrimPrefix (opID , "CreateOrUpdate" )
50
55
} else if strings .HasPrefix (opID , "BatchCreate" ) {
51
56
resName := strings .TrimPrefix (opID , "BatchCreate" )
52
57
if pluralize .IsPlural (resName ) {
53
- return OpTypeCreateBatch , pluralize .Singular (resName )
58
+ // Do not singularize "pluralized singular" resources
59
+ // like EC2's DhcpOptions, if defined in generator config's list of
60
+ // resources.
61
+ if _ , exists := cfg .Resources [resName ]; ! exists {
62
+ return OpTypeCreateBatch , pluralize .Singular (resName )
63
+ }
54
64
}
55
65
return OpTypeCreateBatch , resName
56
66
} else if strings .HasPrefix (opID , "CreateBatch" ) {
57
67
resName := strings .TrimPrefix (opID , "CreateBatch" )
58
68
if pluralize .IsPlural (resName ) {
59
- return OpTypeCreateBatch , pluralize .Singular (resName )
69
+ if _ , exists := cfg .Resources [resName ]; ! exists {
70
+ return OpTypeCreateBatch , pluralize .Singular (resName )
71
+ }
60
72
}
61
73
return OpTypeCreateBatch , resName
62
74
} else if strings .HasPrefix (opID , "Create" ) {
63
75
resName := strings .TrimPrefix (opID , "Create" )
64
76
if pluralize .IsPlural (resName ) {
65
- return OpTypeCreateBatch , pluralize .Singular (resName )
77
+ // If resName exists in the generator configuration's list of
78
+ // resources, then just return OpTypeCreate and the resource name.
79
+ // This handles "pluralized singular" resource names like EC2's
80
+ // DhcpOptions.
81
+ if _ , exists := cfg .Resources [resName ]; ! exists {
82
+ return OpTypeCreateBatch , pluralize .Singular (resName )
83
+ }
66
84
}
67
85
return OpTypeCreate , resName
68
86
} else if strings .HasPrefix (opID , "Modify" ) {
@@ -74,7 +92,10 @@ func GetOpTypeAndResourceNameFromOpID(opID string) (OpType, string) {
74
92
} else if strings .HasPrefix (opID , "Describe" ) {
75
93
resName := strings .TrimPrefix (opID , "Describe" )
76
94
if pluralize .IsPlural (resName ) {
77
- return OpTypeList , pluralize .Singular (resName )
95
+ if _ , exists := cfg .Resources [resName ]; ! exists {
96
+ return OpTypeList , pluralize .Singular (resName )
97
+ }
98
+ return OpTypeList , resName
78
99
}
79
100
return OpTypeGet , resName
80
101
} else if strings .HasPrefix (opID , "Get" ) {
@@ -85,12 +106,20 @@ func GetOpTypeAndResourceNameFromOpID(opID string) (OpType, string) {
85
106
}
86
107
resName := strings .TrimPrefix (opID , "Get" )
87
108
if pluralize .IsPlural (resName ) {
88
- return OpTypeList , pluralize .Singular (resName )
109
+ if _ , exists := cfg .Resources [resName ]; ! exists {
110
+ return OpTypeList , pluralize .Singular (resName )
111
+ }
112
+ return OpTypeList , resName
89
113
}
90
114
return OpTypeGet , resName
91
115
} else if strings .HasPrefix (opID , "List" ) {
92
116
resName := strings .TrimPrefix (opID , "List" )
93
- return OpTypeList , pluralize .Singular (resName )
117
+ if pluralize .IsPlural (resName ) {
118
+ if _ , exists := cfg .Resources [resName ]; ! exists {
119
+ return OpTypeList , pluralize .Singular (resName )
120
+ }
121
+ }
122
+ return OpTypeList , resName
94
123
} else if strings .HasPrefix (opID , "Set" ) {
95
124
if strings .HasSuffix (opID , "Attributes" ) {
96
125
resName := strings .TrimPrefix (opID , "Set" )
0 commit comments