@@ -54,10 +54,23 @@ var detailsRequireKeyValue = map[string]bool{
5454// detailsRequireZeroIndex is a prefilled map with a list of details
5555// that need to be encoded using zero indexing
5656var detailsRequireZeroIndex = map [string ]bool {
57- "registerTemplate" : true ,
58- "updateTemplate" : true ,
59- "createAccount" : true ,
60- "updateAccount" : true ,
57+ "registerTemplate" : true ,
58+ "updateTemplate" : true ,
59+ "createAccount" : true ,
60+ "updateAccount" : true ,
61+ "updateVirtualMachine" : true ,
62+ }
63+
64+ // parametersRequireIndexing contains map parameters that always need
65+ // index variables (i) even when the command uses zero indexing
66+ var parametersRequireIndexing = map [string ]bool {
67+ "userdatadetails" : true ,
68+ "serviceproviderlist" : true ,
69+ "usersecuritygrouplist" : true ,
70+ "tags" : true ,
71+ "nicnetworklist" : true ,
72+ "nicipaddresslist" : true ,
73+ "datadiskofferinglist" : true ,
6174}
6275
6376// requiresPost is a prefilled set of API names that require POST
@@ -1363,7 +1376,11 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
13631376 case "map[string]string" :
13641377 pn ("m := v.(map[string]string)" )
13651378 zeroIndex := detailsRequireZeroIndex [cmd ]
1366- if zeroIndex {
1379+ needsIndex := parametersRequireIndexing [name ]
1380+
1381+ shouldUseStaticZeroIndex := zeroIndex && ! needsIndex
1382+
1383+ if shouldUseStaticZeroIndex {
13671384 pn ("for _, k := range getSortedKeysFromMap(m) {" )
13681385 } else {
13691386 pn ("for i, k := range getSortedKeysFromMap(m) {" )
@@ -1408,7 +1425,7 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
14081425 pn (" u.Set(fmt.Sprintf(\" %s[%%d].name\" , i), k)" , name )
14091426 pn (" u.Set(fmt.Sprintf(\" %s[%%d].value\" , i), m[k])" , name )
14101427 default :
1411- if zeroIndex && ! detailsRequireKeyValue [cmd ] {
1428+ if shouldUseStaticZeroIndex && ! detailsRequireKeyValue [cmd ] {
14121429 pn (" u.Set(fmt.Sprintf(\" %s[0].%%s\" , k), m[k])" , name )
14131430 } else {
14141431 pn (" u.Set(fmt.Sprintf(\" %s[%%d].key\" , i), k)" , name )
0 commit comments