Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions modules/swagger-codegen/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
25 changes: 8 additions & 17 deletions samples/client/petstore/go/go-petstore/pet_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/go/go-petstore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</configuration>
</execution>
<execution>
<id>go-get-sling</id>
<id>go-get-resty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
Expand All @@ -50,7 +50,7 @@
<executable>go</executable>
<arguments>
<argument>get</argument>
<argument>github.com/dghubble/sling</argument>
<argument>github.com/go-resty/resty</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -72,4 +72,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
7 changes: 1 addition & 6 deletions samples/client/petstore/go/go-petstore/store_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 0 additions & 8 deletions samples/client/petstore/go/go-petstore/user_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down