From 5bb1853018713a0d1a75c179dfa7c9c8831f4a03 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Fri, 6 May 2016 11:48:20 -0700 Subject: [PATCH 1/3] added support for multi --- .../src/main/resources/go/api.mustache | 19 +++++++++++--- .../client/petstore/go/go-petstore/pet_api.go | 26 ++++++++++++++++--- .../petstore/go/go-petstore/store_api.go | 4 +++ .../petstore/go/go-petstore/user_api.go | 14 ++++++---- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 480db023f6b..4e80a62482d 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -75,9 +75,22 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{ // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] - }{{#hasQueryParams}}{{#queryParams}} - - queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}) + } + {{#hasQueryParams}} + {{#queryParams}} + {{#isListContainer}} + var collectionFormat = "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}" + if collectionFormat == "multi" { + for _, value := range {{paramName}} { + queryParams["{{paramName}}"] = value + } + } else { + queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}) + } + {{/isListContainer}} + {{^isListContainer}} + queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}) + {{/isListContainer}} {{/queryParams}}{{/hasQueryParams}} // to determine the Content-Type header diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index f70ceaa65f0..8a2172cd8b9 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -64,6 +64,7 @@ func (a PetApi) AddPet(body Pet) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ "application/json", "application/xml", } @@ -132,6 +133,7 @@ func (a PetApi) DeletePet(petId int64, apiKey string) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -198,8 +200,14 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) { for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - - queryParams["status"] = a.Configuration.APIClient.ParameterToString(status) + var collectionFormat = "csv" + if collectionFormat == "multi" { + for _, value := range status { + queryParams["status"] = value + } + } else { + queryParams["status"] = a.Configuration.APIClient.ParameterToString(status) + } // to determine the Content-Type header @@ -264,8 +272,14 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) { for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - - queryParams["tags"] = a.Configuration.APIClient.ParameterToString(tags) + var collectionFormat = "csv" + if collectionFormat == "multi" { + for _, value := range tags { + queryParams["tags"] = value + } + } else { + queryParams["tags"] = a.Configuration.APIClient.ParameterToString(tags) + } // to determine the Content-Type header @@ -331,6 +345,7 @@ func (a PetApi) GetPetById(petId int64) (*Pet, *APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -394,6 +409,7 @@ func (a PetApi) UpdatePet(body Pet) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ "application/json", "application/xml", } @@ -463,6 +479,7 @@ func (a PetApi) UpdatePetWithForm(petId int64, name string, status string) (*API headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ "application/x-www-form-urlencoded", } @@ -532,6 +549,7 @@ func (a PetApi) UploadFile(petId int64, additionalMetadata string, file *os.File headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ "multipart/form-data", } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 56af7223639..e84bf251469 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -58,6 +58,7 @@ func (a StoreApi) DeleteOrder(orderId string) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -115,6 +116,7 @@ func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -173,6 +175,7 @@ func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -231,6 +234,7 @@ func (a StoreApi) PlaceOrder(body Order) (*Order, *APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 1ed8b9a599a..a2b90c7b737 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -57,6 +57,7 @@ func (a UserApi) CreateUser(body User) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -118,6 +119,7 @@ func (a UserApi) CreateUsersWithArrayInput(body []User) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -179,6 +181,7 @@ func (a UserApi) CreateUsersWithListInput(body []User) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -241,6 +244,7 @@ func (a UserApi) DeleteUser(username string) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -300,6 +304,7 @@ func (a UserApi) GetUserByName(username string) (*User, *APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -362,11 +367,8 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - - queryParams["username"] = a.Configuration.APIClient.ParameterToString(username) - - - queryParams["password"] = a.Configuration.APIClient.ParameterToString(password) + queryParams["username"] = a.Configuration.APIClient.ParameterToString(username) + queryParams["password"] = a.Configuration.APIClient.ParameterToString(password) // to determine the Content-Type header @@ -422,6 +424,7 @@ func (a UserApi) LogoutUser() (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } @@ -486,6 +489,7 @@ func (a UserApi) UpdateUser(username string, body User) (*APIResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } + // to determine the Content-Type header localVarHttpContentTypes := []string{ } From 0bc34dcae8696a001aaecdd77e5f081782c8d48c Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Fri, 6 May 2016 23:48:46 -0700 Subject: [PATCH 2/3] updated api_client.go to use the new SetMultiValueQueryParams method --- .../src/main/resources/go/api.mustache | 9 ++++--- .../src/main/resources/go/api_client.mustache | 8 +++--- .../petstore/go/go-petstore/api_client.go | 8 +++--- .../client/petstore/go/go-petstore/pet_api.go | 25 ++++++++++--------- .../petstore/go/go-petstore/store_api.go | 9 ++++--- .../petstore/go/go-petstore/user_api.go | 21 ++++++++-------- 6 files changed, 42 insertions(+), 38 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 4e80a62482d..6402a0ced76 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -5,6 +5,7 @@ import ( "strings" "fmt" "errors" + "net/url" {{#imports}}"{{import}}" {{/imports}} ) @@ -50,7 +51,7 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{ }{{/required}}{{/allParams}} headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -82,14 +83,14 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{ var collectionFormat = "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}" if collectionFormat == "multi" { for _, value := range {{paramName}} { - queryParams["{{paramName}}"] = value + queryParams.Add("{{paramName}}", value) } } else { - queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}) + queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}})) } {{/isListContainer}} {{^isListContainer}} - queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}) + queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}})) {{/isListContainer}} {{/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 88c5ce07e4e..c4e6c635227 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -6,7 +6,7 @@ import ( "path/filepath" "reflect" "strings" - + "net/url" "github.com/go-resty/resty" ) @@ -47,7 +47,7 @@ func contains(source []string, containvalue string) bool { func (c *APIClient) CallAPI(path string, method string, postBody interface{}, headerParams map[string]string, - queryParams map[string]string, + queryParams url.Values, formParams map[string]string, fileName string, fileBytes []byte) (*resty.Response, error) { @@ -89,7 +89,7 @@ func (c *APIClient) ParameterToString(obj interface{}) string { func prepareRequest(postBody interface{}, headerParams map[string]string, - queryParams map[string]string, + queryParams url.Values, formParams map[string]string, fileName string, fileBytes []byte) *resty.Request { @@ -104,7 +104,7 @@ func prepareRequest(postBody interface{}, // add query parameter, if any if len(queryParams) > 0 { - request.SetQueryParams(queryParams) + request.SetMultiValueQueryParams(queryParams) } // add form parameter, if any diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 100a36da7e1..25e91cabbd0 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -6,7 +6,7 @@ import ( "path/filepath" "reflect" "strings" - + "net/url" "github.com/go-resty/resty" ) @@ -47,7 +47,7 @@ func contains(source []string, containvalue string) bool { func (c *APIClient) CallAPI(path string, method string, postBody interface{}, headerParams map[string]string, - queryParams map[string]string, + queryParams url.Values, formParams map[string]string, fileName string, fileBytes []byte) (*resty.Response, error) { @@ -89,7 +89,7 @@ func (c *APIClient) ParameterToString(obj interface{}) string { func prepareRequest(postBody interface{}, headerParams map[string]string, - queryParams map[string]string, + queryParams url.Values, formParams map[string]string, fileName string, fileBytes []byte) *resty.Request { @@ -104,7 +104,7 @@ func prepareRequest(postBody interface{}, // add query parameter, if any if len(queryParams) > 0 { - request.SetQueryParams(queryParams) + request.SetMultiValueQueryParams(queryParams) } // add form parameter, if any diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 8a2172cd8b9..613006aef1a 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -4,6 +4,7 @@ import ( "strings" "fmt" "errors" + "net/url" "os" "io/ioutil" "encoding/json" @@ -48,7 +49,7 @@ func (a PetApi) AddPet(body Pet) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -117,7 +118,7 @@ func (a PetApi) DeletePet(petId int64, apiKey string) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -185,7 +186,7 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -203,10 +204,10 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) { var collectionFormat = "csv" if collectionFormat == "multi" { for _, value := range status { - queryParams["status"] = value + queryParams.Add("status", value) } } else { - queryParams["status"] = a.Configuration.APIClient.ParameterToString(status) + queryParams.Add("status", a.Configuration.APIClient.ParameterToString(status)) } @@ -257,7 +258,7 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -275,10 +276,10 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) { var collectionFormat = "csv" if collectionFormat == "multi" { for _, value := range tags { - queryParams["tags"] = value + queryParams.Add("tags", value) } } else { - queryParams["tags"] = a.Configuration.APIClient.ParameterToString(tags) + queryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags)) } @@ -330,7 +331,7 @@ func (a PetApi) GetPetById(petId int64) (*Pet, *APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -393,7 +394,7 @@ func (a PetApi) UpdatePet(body Pet) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -463,7 +464,7 @@ func (a PetApi) UpdatePetWithForm(petId int64, name string, status string) (*API } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -533,7 +534,7 @@ func (a PetApi) UploadFile(petId int64, additionalMetadata string, file *os.File } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index e84bf251469..9e24fe68b53 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -4,6 +4,7 @@ import ( "strings" "fmt" "errors" + "net/url" "encoding/json" ) @@ -47,7 +48,7 @@ func (a StoreApi) DeleteOrder(orderId string) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -101,7 +102,7 @@ func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) { headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -164,7 +165,7 @@ func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -223,7 +224,7 @@ func (a StoreApi) PlaceOrder(body Order) (*Order, *APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index a2b90c7b737..150bea6752d 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -4,6 +4,7 @@ import ( "strings" "fmt" "errors" + "net/url" "encoding/json" ) @@ -46,7 +47,7 @@ func (a UserApi) CreateUser(body User) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -108,7 +109,7 @@ func (a UserApi) CreateUsersWithArrayInput(body []User) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -170,7 +171,7 @@ func (a UserApi) CreateUsersWithListInput(body []User) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -233,7 +234,7 @@ func (a UserApi) DeleteUser(username string) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -293,7 +294,7 @@ func (a UserApi) GetUserByName(username string) (*User, *APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -357,7 +358,7 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -367,8 +368,8 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["username"] = a.Configuration.APIClient.ParameterToString(username) - queryParams["password"] = a.Configuration.APIClient.ParameterToString(password) + queryParams.Add("username", a.Configuration.APIClient.ParameterToString(username)) + queryParams.Add("password", a.Configuration.APIClient.ParameterToString(password)) // to determine the Content-Type header @@ -413,7 +414,7 @@ func (a UserApi) LogoutUser() (*APIResponse, error) { headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string @@ -478,7 +479,7 @@ func (a UserApi) UpdateUser(username string, body User) (*APIResponse, error) { } headerParams := make(map[string]string) - queryParams := make(map[string]string) + queryParams := url.Values{} formParams := make(map[string]string) var postBody interface{} var fileName string From e7f68287c114e4b429feaf77b3bc396c147bf607 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 9 May 2016 22:01:32 -0700 Subject: [PATCH 3/3] updated function to support multiple collection formats --- .../src/main/resources/go/api.mustache | 4 ++-- .../src/main/resources/go/api_client.mustache | 17 +++++++++++++---- .../petstore/go/go-petstore/api_client.go | 17 +++++++++++++---- .../client/petstore/go/go-petstore/pet_api.go | 4 ++-- .../client/petstore/go/go-petstore/user_api.go | 4 ++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 6402a0ced76..ee828484ef3 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -86,11 +86,11 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{ queryParams.Add("{{paramName}}", value) } } else { - queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}})) + queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, collectionFormat)) } {{/isListContainer}} {{^isListContainer}} - queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}})) + queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, "")) {{/isListContainer}} {{/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 c4e6c635227..2fa6d14ef2b 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -79,12 +79,21 @@ func (c *APIClient) CallAPI(path string, method string, return nil, fmt.Errorf("invalid method %v", method) } -func (c *APIClient) ParameterToString(obj interface{}) string { +func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) string { if reflect.TypeOf(obj).String() == "[]string" { - return strings.Join(obj.([]string), ",") - } else { - return obj.(string) + switch collectionFormat { + case "pipes": + return strings.Join(obj.([]string), "|") + case "ssv": + return strings.Join(obj.([]string), " ") + case "tsv": + return strings.Join(obj.([]string), "\t") + case "csv" : + return strings.Join(obj.([]string), ",") + } } + + return obj.(string) } func prepareRequest(postBody interface{}, diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 25e91cabbd0..fe73dc5682a 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -79,12 +79,21 @@ func (c *APIClient) CallAPI(path string, method string, return nil, fmt.Errorf("invalid method %v", method) } -func (c *APIClient) ParameterToString(obj interface{}) string { +func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) string { if reflect.TypeOf(obj).String() == "[]string" { - return strings.Join(obj.([]string), ",") - } else { - return obj.(string) + switch collectionFormat { + case "pipes": + return strings.Join(obj.([]string), "|") + case "ssv": + return strings.Join(obj.([]string), " ") + case "tsv": + return strings.Join(obj.([]string), "\t") + case "csv" : + return strings.Join(obj.([]string), ",") + } } + + return obj.(string) } func prepareRequest(postBody interface{}, diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 613006aef1a..34efe36d9be 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, *APIResponse, error) { queryParams.Add("status", value) } } else { - queryParams.Add("status", a.Configuration.APIClient.ParameterToString(status)) + queryParams.Add("status", a.Configuration.APIClient.ParameterToString(status, collectionFormat)) } @@ -279,7 +279,7 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) { queryParams.Add("tags", value) } } else { - queryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags)) + queryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags, collectionFormat)) } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 150bea6752d..af0ea7b85f5 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -368,8 +368,8 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams.Add("username", a.Configuration.APIClient.ParameterToString(username)) - queryParams.Add("password", a.Configuration.APIClient.ParameterToString(password)) + queryParams.Add("username", a.Configuration.APIClient.ParameterToString(username, "")) + queryParams.Add("password", a.Configuration.APIClient.ParameterToString(password, "")) // to determine the Content-Type header