Skip to content

Commit

Permalink
Force parameters to be required to maintain backward compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh92 committed Mar 5, 2024
1 parent afbda39 commit da9a13b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SHELL = /usr/bin/env bash -o pipefail
all: code mocks test

code:
go run generate/generate.go generate/layout.go --api=generate/listApis.json
go run generate/generate.go generate/layout.go generate/requiredParams.go --api=generate/listApis.json

FILES=$(shell for file in `pwd`/cloudstack/*Service.go ;do basename $$file .go ; done)
mocks:
Expand Down
16 changes: 15 additions & 1 deletion generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,14 @@ func (s *service) generateInterfaceType() {
p("New%s(", tn)
for _, ap := range api.Params {
if ap.Required {
// rp = append(rp, ap)
p("%s %s, ", s.parseParamName(ap.Name), mapType(api.Name, ap.Name, ap.Type))
} else if params, ok := requiredParams[api.Name]; ok {
for _, param := range params {
if param == ap.Name {
p("%s %s, ", s.parseParamName(ap.Name), mapType(api.Name, ap.Name, ap.Type))
break
}
}
}
}
pn(") *%s", tn)
Expand Down Expand Up @@ -1423,6 +1429,14 @@ func (s *service) generateNewParamTypeFunc(a *API) {
if ap.Required {
rp = append(rp, ap)
p("%s %s, ", s.parseParamName(ap.Name), mapType(a.Name, ap.Name, ap.Type))
} else if params, ok := requiredParams[a.Name]; ok {
for _, param := range params {
if param == ap.Name {
rp = append(rp, ap)
p("%s %s, ", s.parseParamName(ap.Name), mapType(a.Name, ap.Name, ap.Type))
break
}
}
}
}
pn(") *%s {", tn)
Expand Down
54 changes: 54 additions & 0 deletions generate/requiredParams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package main

// This map contains the API commands and the parameters which needs to be made
// made required to ensure backward compatibility with the older versions of
// the CloudStack API.

var requiredParams = map[string][]string{
"createNetworkOffering": {
"displaytext",
},
"createDiskOffering": {
"displaytext",
},
"createServiceOffering": {
"displaytext",
},
"createVPCOffering": {
"displaytext",
},
"registerIso": {
"displaytext",
},
"createProject": {
"displaytext",
},
"createTemplate": {
"displaytext",
},
"registerTemplate": {
"displaytext",
},
"createVPC": {
"displaytext",
},
}

0 comments on commit da9a13b

Please sign in to comment.