Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cloudstack/VirtualMachineService.go
Original file line number Diff line number Diff line change
Expand Up @@ -9858,8 +9858,8 @@ func (p *UpdateVirtualMachineParams) toURLValues() url.Values {
}
if v, found := p.p["details"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k])
for _, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("details[0].%s", k), m[k])
}
}
if v, found := p.p["dhcpoptionsnetworklist"]; found {
Expand Down
29 changes: 23 additions & 6 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,23 @@ var detailsRequireKeyValue = map[string]bool{
// detailsRequireZeroIndex is a prefilled map with a list of details
// that need to be encoded using zero indexing
var detailsRequireZeroIndex = map[string]bool{
"registerTemplate": true,
"updateTemplate": true,
"createAccount": true,
"updateAccount": true,
"registerTemplate": true,
"updateTemplate": true,
"createAccount": true,
"updateAccount": true,
"updateVirtualMachine": true,
}

// parametersRequireIndexing contains map parameters that always need
// index variables (i) even when the command uses zero indexing
var parametersRequireIndexing = map[string]bool{
"userdatadetails": true,
"serviceproviderlist": true,
"usersecuritygrouplist": true,
"tags": true,
"nicnetworklist": true,
"nicipaddresslist": true,
"datadiskofferinglist": true,
}

// requiresPost is a prefilled set of API names that require POST
Expand Down Expand Up @@ -1363,7 +1376,11 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
case "map[string]string":
pn("m := v.(map[string]string)")
zeroIndex := detailsRequireZeroIndex[cmd]
if zeroIndex {
needsIndex := parametersRequireIndexing[name]

shouldUseStaticZeroIndex := zeroIndex && !needsIndex

if shouldUseStaticZeroIndex {
pn("for _, k := range getSortedKeysFromMap(m) {")
} else {
pn("for i, k := range getSortedKeysFromMap(m) {")
Expand Down Expand Up @@ -1408,7 +1425,7 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
pn(" u.Set(fmt.Sprintf(\"%s[%%d].name\", i), k)", name)
pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), m[k])", name)
default:
if zeroIndex && !detailsRequireKeyValue[cmd] {
if shouldUseStaticZeroIndex && !detailsRequireKeyValue[cmd] {
pn(" u.Set(fmt.Sprintf(\"%s[0].%%s\", k), m[k])", name)
} else {
pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", name)
Expand Down
Loading