From 2fcda964adc0b5b1ce526dc9e75ae2f70525983a Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 18 Apr 2016 23:06:18 -0700 Subject: [PATCH] added ParameterToString method to handle string array issue --- .../swagger-codegen/src/main/resources/go/api.mustache | 2 +- .../src/main/resources/go/api_client.mustache | 9 +++++++++ samples/client/petstore/go/go-petstore/api_client.go | 9 +++++++++ samples/client/petstore/go/go-petstore/pet_api.go | 6 +++--- samples/client/petstore/go/go-petstore/user_api.go | 4 ++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 0edb1a7d5c9..14106c25ddf 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -92,7 +92,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#hasQueryParams}} {{#queryParams}} - queryParams["{{vendorExtensions.x-exportParamName}}"] = strings.Join({{paramName}}, ",") + queryParams["{{vendorExtensions.x-exportParamName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) {{/queryParams}} {{/hasQueryParams}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index a4f06b30828..ad2d148e052 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -4,6 +4,7 @@ import ( "strings" "github.com/go-resty/resty" "errors" + "reflect" ) type ApiClient struct { @@ -73,6 +74,14 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } +func (c *ApiClient) ParameterToString (obj interface{}) string { + if reflect.TypeOf(obj).Len() > 0 { + return strings.Join(obj.([]string), ",") + } else{ + return obj.(string) + } +} + func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index e8bc409811d..3440a83a9fd 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/go-resty/resty" "errors" + "reflect" ) type ApiClient struct { @@ -73,6 +74,14 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } +func (c *ApiClient) ParameterToString (obj interface{}) string { + if reflect.TypeOf(obj).Len() > 0 { + return strings.Join(obj.([]string), ",") + } else{ + return obj.(string) + } +} + func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 9b0debc95ac..63a2c6a3627 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -207,7 +207,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Status"] = strings.Join(status, ",") + queryParams["Status"] = a.Configuration.ApiClient.ParameterToString(status) // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -277,7 +277,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Tags"] = strings.Join(tags, ",") + queryParams["Tags"] = a.Configuration.ApiClient.ParameterToString(tags) // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -585,7 +585,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil } formParams["AdditionalMetadata"] = additionalMetadata - formParams["File"] = file + formParams["File"] = file.Name() var successPayload = new(ApiResponse) diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index a53788439f1..2d5dc5fb8d5 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -380,8 +380,8 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Username"] = strings.Join(username, ",") - queryParams["Password"] = strings.Join(password, ",") + queryParams["Username"] = a.Configuration.ApiClient.ParameterToString(username) + queryParams["Password"] = a.Configuration.ApiClient.ParameterToString(password) // to determine the Content-Type header localVarHttpContentTypes := []string {