From da9a13b9f502c949403f553d4627b70c48221838 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Wed, 6 Mar 2024 01:48:39 +0530 Subject: [PATCH] Force parameters to be required to maintain backward compatability --- Makefile | 2 +- generate/generate.go | 16 ++++++++++- generate/requiredParams.go | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 generate/requiredParams.go diff --git a/Makefile b/Makefile index f69f7c3d..9fca7776 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/generate/generate.go b/generate/generate.go index 0a5b09ad..f13af0aa 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -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) @@ -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) diff --git a/generate/requiredParams.go b/generate/requiredParams.go new file mode 100644 index 00000000..33d1e742 --- /dev/null +++ b/generate/requiredParams.go @@ -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", + }, +}