From 5bb1853018713a0d1a75c179dfa7c9c8831f4a03 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Fri, 6 May 2016 11:48:20 -0700 Subject: [PATCH] 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{ }