From 9386e4c04b9318eabc3148e775d2b451e3f10de7 Mon Sep 17 00:00:00 2001 From: AnuGayan Date: Mon, 29 Jul 2024 09:18:21 +0530 Subject: [PATCH] Allow exporting APIs with spaces in the name --- import-export-cli/cmd/exportAPI.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/import-export-cli/cmd/exportAPI.go b/import-export-cli/cmd/exportAPI.go index c705d9d0..9c3abbf0 100644 --- a/import-export-cli/cmd/exportAPI.go +++ b/import-export-cli/cmd/exportAPI.go @@ -20,12 +20,12 @@ package cmd import ( "fmt" + "github.com/wso2/product-apim-tooling/import-export-cli/credentials" "io/ioutil" + "net/url" "os" "strconv" - "github.com/wso2/product-apim-tooling/import-export-cli/credentials" - "github.com/go-resty/resty/v2" "github.com/spf13/cobra" "github.com/wso2/product-apim-tooling/import-export-cli/utils" @@ -132,20 +132,19 @@ func WriteToZip(exportAPIName, exportAPIVersion, zipLocationPath string, resp *r // @return response Response in the form of *resty.Response func getExportApiResponse(name, version, provider, format, apiImportExportEndpoint, b64encodedCredentials string, preserveStatus bool, ignoreSwagger bool) (*resty.Response, error) { apiImportExportEndpoint = utils.AppendSlashToString(apiImportExportEndpoint) - query := "export-api?name=" + name + "&version=" + version + "&provider=" + provider + + query := "export-api?name=" + url.QueryEscape(name) + "&version=" + version + "&provider=" + provider + "&preserveStatus=" + strconv.FormatBool(preserveStatus) + "&ignoreSwagger=" + strconv.FormatBool(ignoreSwagger) if format != "" { query += "&format=" + format } - - url := apiImportExportEndpoint + query - utils.Logln(utils.LogPrefixInfo+"ExportAPI: URL:", url) + urlString := apiImportExportEndpoint + query + utils.Logln(utils.LogPrefixInfo+"ExportAPI: URL:", urlString) headers := make(map[string]string) headers[utils.HeaderAuthorization] = utils.HeaderValueAuthBasicPrefix + " " + b64encodedCredentials headers[utils.HeaderAccept] = utils.HeaderValueApplicationZip - resp, err := utils.InvokeGETRequest(url, headers) + resp, err := utils.InvokeGETRequest(urlString, headers) if err != nil { return nil, err