@@ -43,6 +43,21 @@ const (
43
43
44
44
type OperationMap map [OpType ]map [string ]* awssdkmodel.Operation
45
45
46
+ // resourceExistsInConfig returns true if the supplied resource name exists in
47
+ // the supplied Config object's Resources collection, case-insensitive
48
+ // matching.
49
+ func resourceExistsInConfig (
50
+ subject string ,
51
+ cfg * ackgenconfig.Config ,
52
+ ) bool {
53
+ for resName := range cfg .Resources {
54
+ if strings .EqualFold (resName , subject ) {
55
+ return true
56
+ }
57
+ }
58
+ return false
59
+ }
60
+
46
61
// GetOpTypeAndResourceNameFromOpID guesses the resource name and type of
47
62
// operation from the OperationID
48
63
func GetOpTypeAndResourceNameFromOpID (
@@ -58,17 +73,19 @@ func GetOpTypeAndResourceNameFromOpID(
58
73
// Do not singularize "pluralized singular" resources
59
74
// like EC2's DhcpOptions, if defined in generator config's list of
60
75
// resources.
61
- if _ , exists := cfg . Resources [ resName ]; ! exists {
62
- return OpTypeCreateBatch , pluralize . Singular ( resName )
76
+ if resourceExistsInConfig ( resName , cfg ) {
77
+ return OpTypeCreateBatch , resName
63
78
}
79
+ return OpTypeCreateBatch , pluralize .Singular (resName )
64
80
}
65
81
return OpTypeCreateBatch , resName
66
82
} else if strings .HasPrefix (opID , "CreateBatch" ) {
67
83
resName := strings .TrimPrefix (opID , "CreateBatch" )
68
84
if pluralize .IsPlural (resName ) {
69
- if _ , exists := cfg . Resources [ resName ]; ! exists {
70
- return OpTypeCreateBatch , pluralize . Singular ( resName )
85
+ if resourceExistsInConfig ( resName , cfg ) {
86
+ return OpTypeCreateBatch , resName
71
87
}
88
+ return OpTypeCreateBatch , pluralize .Singular (resName )
72
89
}
73
90
return OpTypeCreateBatch , resName
74
91
} else if strings .HasPrefix (opID , "Create" ) {
@@ -78,9 +95,10 @@ func GetOpTypeAndResourceNameFromOpID(
78
95
// resources, then just return OpTypeCreate and the resource name.
79
96
// This handles "pluralized singular" resource names like EC2's
80
97
// DhcpOptions.
81
- if _ , exists := cfg . Resources [ resName ]; ! exists {
82
- return OpTypeCreateBatch , pluralize . Singular ( resName )
98
+ if resourceExistsInConfig ( resName , cfg ) {
99
+ return OpTypeCreate , resName
83
100
}
101
+ return OpTypeCreateBatch , pluralize .Singular (resName )
84
102
}
85
103
return OpTypeCreate , resName
86
104
} else if strings .HasPrefix (opID , "Modify" ) {
@@ -92,10 +110,10 @@ func GetOpTypeAndResourceNameFromOpID(
92
110
} else if strings .HasPrefix (opID , "Describe" ) {
93
111
resName := strings .TrimPrefix (opID , "Describe" )
94
112
if pluralize .IsPlural (resName ) {
95
- if _ , exists := cfg . Resources [ resName ]; ! exists {
96
- return OpTypeList , pluralize . Singular ( resName )
113
+ if resourceExistsInConfig ( resName , cfg ) {
114
+ return OpTypeGet , resName
97
115
}
98
- return OpTypeList , resName
116
+ return OpTypeList , pluralize . Singular ( resName )
99
117
}
100
118
return OpTypeGet , resName
101
119
} else if strings .HasPrefix (opID , "Get" ) {
@@ -106,18 +124,19 @@ func GetOpTypeAndResourceNameFromOpID(
106
124
}
107
125
resName := strings .TrimPrefix (opID , "Get" )
108
126
if pluralize .IsPlural (resName ) {
109
- if _ , exists := cfg . Resources [ resName ]; ! exists {
110
- return OpTypeList , pluralize . Singular ( resName )
127
+ if resourceExistsInConfig ( resName , cfg ) {
128
+ return OpTypeGet , resName
111
129
}
112
- return OpTypeList , resName
130
+ return OpTypeList , pluralize . Singular ( resName )
113
131
}
114
132
return OpTypeGet , resName
115
133
} else if strings .HasPrefix (opID , "List" ) {
116
134
resName := strings .TrimPrefix (opID , "List" )
117
135
if pluralize .IsPlural (resName ) {
118
- if _ , exists := cfg . Resources [ resName ]; ! exists {
119
- return OpTypeList , pluralize . Singular ( resName )
136
+ if resourceExistsInConfig ( resName , cfg ) {
137
+ return OpTypeList , resName
120
138
}
139
+ return OpTypeList , pluralize .Singular (resName )
121
140
}
122
141
return OpTypeList , resName
123
142
} else if strings .HasPrefix (opID , "Set" ) {
0 commit comments