diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 6ddb9ee2753..9880c5b3b99 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -58,22 +58,30 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType} var fileName string var fileBytes []byte {{#authMethods}} - // authentication ({{name}}) required -{{#isApiKey}}{{#isKeyInHeader}} + // authentication '({{name}})' required +{{#isApiKey}} +{{#isKeyInHeader}} // set key with prefix in header headerParams["{{keyParamName}}"] = a.Configuration.GetAPIKeyWithPrefix("{{keyParamName}}") -{{/isKeyInHeader}}{{#isKeyInQuery}} - // set key with prefix in querystring{{#hasKeyParamName}} +{{/isKeyInHeader}} +{{#isKeyInQuery}} + // set key with prefix in query string queryParams["{{keyParamName}}"] = a.Configuration.GetAPIKeyWithPrefix("{{keyParamName}}") -{{/hasKeyParamName}}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}} +{{/isKeyInQuery}} +{{/isApiKey}} +{{#isBasic}} // http basic authentication required if a.Configuration.Username != "" || a.Configuration.Password != ""{ headerParams["Authorization"] = "Basic " + a.Configuration.GetBasicAuthEncodedString() - }{{/isBasic}}{{#isOAuth}} + } +{{/isBasic}} +{{#isOAuth}} // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - }{{/isOAuth}}{{/authMethods}} + } +{{/isOAuth}} +{{/authMethods}} // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] diff --git a/samples/client/petstore/go/go-petstore/README.md b/samples/client/petstore/go/go-petstore/README.md index 5d6a957aa1e..dd7d1da39ed 100644 --- a/samples/client/petstore/go/go-petstore/README.md +++ b/samples/client/petstore/go/go-petstore/README.md @@ -7,7 +7,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-26T21:47:25.590-07:00 +- Build date: 2016-07-26T22:50:03.821+08:00 - Build package: class io.swagger.codegen.languages.GoClientCodegen ## Installation @@ -57,6 +57,12 @@ Class | Method | HTTP request | Description ## Documentation For Authorization +## api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ## petstore_auth - **Type**: OAuth @@ -66,12 +72,6 @@ Class | Method | HTTP request | Description - **write:pets**: modify pets in your account - **read:pets**: read your pets -## api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ## Author diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 132ca3949fb..ea1fec2f8c5 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -115,7 +115,7 @@ func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) s } } - return obj.(string) + return fmt.Sprintf("%v", obj) } 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 07dc51eb90e..d02ac6955a0 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -76,8 +76,7 @@ func (a PetApi) AddPet(body Pet) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken @@ -145,8 +144,7 @@ func (a PetApi) DeletePet(petId int64, apiKey string) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken @@ -213,8 +211,7 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken @@ -285,8 +282,7 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken @@ -358,11 +354,9 @@ func (a PetApi) GetPetById(petId int64) (*Pet, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (api_key) required - + // authentication '(api_key)' required // set key with prefix in header headerParams["api_key"] = a.Configuration.GetAPIKeyWithPrefix("api_key") - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -421,8 +415,7 @@ func (a PetApi) UpdatePet(body Pet) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken @@ -491,8 +484,7 @@ func (a PetApi) UpdatePetWithForm(petId int64, name string, status string) (*API var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken @@ -561,8 +553,7 @@ func (a PetApi) UploadFile(petId int64, additionalMetadata string, file *os.File var postBody interface{} var fileName string var fileBytes []byte - // authentication (petstore_auth) required - + // authentication '(petstore_auth)' required // oauth required if a.Configuration.AccessToken != ""{ headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken diff --git a/samples/client/petstore/go/go-petstore/pom.xml b/samples/client/petstore/go/go-petstore/pom.xml index 7680ed95cff..ab57225649c 100644 --- a/samples/client/petstore/go/go-petstore/pom.xml +++ b/samples/client/petstore/go/go-petstore/pom.xml @@ -41,7 +41,7 @@ - go-get-sling + go-get-resty pre-integration-test exec @@ -50,7 +50,7 @@ go get - github.com/dghubble/sling + github.com/go-resty/resty @@ -72,4 +72,4 @@ - \ No newline at end of file + diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index e2de74695ee..93a34d3470a 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -75,7 +75,6 @@ func (a StoreApi) DeleteOrder(orderId string) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -129,11 +128,9 @@ func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // authentication (api_key) required - + // authentication '(api_key)' required // set key with prefix in header headerParams["api_key"] = a.Configuration.GetAPIKeyWithPrefix("api_key") - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -192,7 +189,6 @@ func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -251,7 +247,6 @@ func (a StoreApi) PlaceOrder(body Order) (*Order, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 2cd9ed6605c..3ef993addb9 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -74,7 +74,6 @@ func (a UserApi) CreateUser(body User) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -136,7 +135,6 @@ func (a UserApi) CreateUsersWithArrayInput(body []User) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -198,7 +196,6 @@ func (a UserApi) CreateUsersWithListInput(body []User) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -261,7 +258,6 @@ func (a UserApi) DeleteUser(username string) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -321,7 +317,6 @@ func (a UserApi) GetUserByName(username string) (*User, *APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -385,7 +380,6 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -441,7 +435,6 @@ func (a UserApi) LogoutUser() (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -506,7 +499,6 @@ func (a UserApi) UpdateUser(username string, body User) (*APIResponse, error) { var postBody interface{} var fileName string var fileBytes []byte - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key]