diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index d02bb0a75e0..57c07808b4e 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -196,7 +196,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}({{#hasAuthMethods}}ctx context.C } else { key = auth.Key } - {{#isKeyInHeader}}localVarHeaderParams["{{keyParamName}}"] = key{{/isKeyInHeader}}{{#isKeyInQuery}}localVarQueryParams['{{keyParamName}}'] = key{{/isKeyInQuery}} + {{#isKeyInHeader}}localVarHeaderParams["{{keyParamName}}"] = key{{/isKeyInHeader}}{{#isKeyInQuery}}localVarQueryParams.Add("{{keyParamName}}", key){{/isKeyInQuery}} } } {{/isApiKey}} diff --git a/samples/client/petstore-security-test/go/.swagger-codegen/VERSION b/samples/client/petstore-security-test/go/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore-security-test/go/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/go/api_client.go b/samples/client/petstore-security-test/go/api_client.go index 98cbc1f1c26..948f60420ea 100644 --- a/samples/client/petstore-security-test/go/api_client.go +++ b/samples/client/petstore-security-test/go/api_client.go @@ -255,6 +255,11 @@ func (c *APIClient) prepareRequest ( } localVarRequest.Header = headers } + + // Override request host, if applicable + if c.cfg.Host != "" { + localVarRequest.Host = c.cfg.Host + } // Add the user agent to the request. localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) diff --git a/samples/client/petstore/go/go-petstore/README.md b/samples/client/petstore/go/go-petstore/README.md index d13ca8c1b41..41a3a1ab7cb 100644 --- a/samples/client/petstore/go/go-petstore/README.md +++ b/samples/client/petstore/go/go-petstore/README.md @@ -21,6 +21,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*AnotherFakeApi* | [**TestSpecialTags**](docs/AnotherFakeApi.md#testspecialtags) | **Patch** /another-fake/dummy | To test special tags *FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **Post** /fake/outer/boolean | *FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **Post** /fake/outer/composite | *FakeApi* | [**FakeOuterNumberSerialize**](docs/FakeApi.md#fakeouternumberserialize) | **Post** /fake/outer/number | @@ -29,7 +30,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **Post** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **Get** /fake | To test enum parameters *FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **Get** /fake/jsonFormData | test json serialization of form data -*Fake_classname_tags123Api* | [**TestClassname**](docs/Fake_classname_tags123Api.md#testclassname) | **Patch** /fake_classname_test | To test class name in snake case +*FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **Patch** /fake_classname_test | To test class name in snake case *PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **Post** /pet | Add a new pet to the store *PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **Delete** /pet/{petId} | Deletes a pet *PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **Get** /pet/findByStatus | Finds Pets by status @@ -97,6 +98,17 @@ Class | Method | HTTP request | Description ## api_key - **Type**: API key +Example +``` + auth := context.WithValue(context.TODO(), sw.ContextAPIKey, sw.APIKey{ + Key: "APIKEY", + Prefix: "Bearer", // Omit if not necessary. + }) + r, err := client.Service.Operation(auth, args) +``` +## api_key_query +- **Type**: API key + Example ``` auth := context.WithValue(context.TODO(), sw.ContextAPIKey, sw.APIKey{ diff --git a/samples/client/petstore/go/go-petstore/another_fake_api.go b/samples/client/petstore/go/go-petstore/another_fake_api.go new file mode 100644 index 00000000000..7953340a72e --- /dev/null +++ b/samples/client/petstore/go/go-petstore/another_fake_api.go @@ -0,0 +1,93 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package petstore + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type AnotherFakeApiService service + + +/* AnotherFakeApiService To test special tags + To test special tags + + @param body client model + @return Client*/ +func (a *AnotherFakeApiService) TestSpecialTags(body Client) (Client, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Patch") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Client + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/another-fake/dummy" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &body + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + + return successPayload, localVarHttpResponse, err +} + diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 06a8add219d..3827a42128d 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -44,8 +44,9 @@ type APIClient struct { common service // Reuse a single struct instead of allocating one for each service on the heap. // API Services + AnotherFakeApi *AnotherFakeApiService FakeApi *FakeApiService - Fake_classname_tags123Api *Fake_classname_tags123ApiService + FakeClassnameTags123Api *FakeClassnameTags123ApiService PetApi *PetApiService StoreApi *StoreApiService UserApi *UserApiService @@ -67,8 +68,9 @@ func NewAPIClient(cfg *Configuration) *APIClient { c.common.client = c // API Services + c.AnotherFakeApi = (*AnotherFakeApiService)(&c.common) c.FakeApi = (*FakeApiService)(&c.common) - c.Fake_classname_tags123Api = (*Fake_classname_tags123ApiService)(&c.common) + c.FakeClassnameTags123Api = (*FakeClassnameTags123ApiService)(&c.common) c.PetApi = (*PetApiService)(&c.common) c.StoreApi = (*StoreApiService)(&c.common) c.UserApi = (*UserApiService)(&c.common) diff --git a/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md b/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md new file mode 100644 index 00000000000..771589380bc --- /dev/null +++ b/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md @@ -0,0 +1,36 @@ +# \AnotherFakeApi + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**TestSpecialTags**](AnotherFakeApi.md#TestSpecialTags) | **Patch** /another-fake/dummy | To test special tags + + +# **TestSpecialTags** +> Client TestSpecialTags(body) +To test special tags + +To test special tags + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Client**](Client.md)| client model | + +### Return type + +[**Client**](Client.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md b/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md new file mode 100644 index 00000000000..921c76f3df4 --- /dev/null +++ b/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md @@ -0,0 +1,35 @@ +# \FakeClassnameTags123Api + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**TestClassname**](FakeClassnameTags123Api.md#TestClassname) | **Patch** /fake_classname_test | To test class name in snake case + + +# **TestClassname** +> Client TestClassname(ctx, body) +To test class name in snake case + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ctx** | **context.Context** | context containing the authentication | nil if no authentication + **body** | [**Client**](Client.md)| client model | + +### Return type + +[**Client**](Client.md) + +### Authorization + +[api_key_query](../README.md#api_key_query) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/go/go-petstore/docs/StoreApi.md b/samples/client/petstore/go/go-petstore/docs/StoreApi.md index fcc8d674d25..3908de6a544 100644 --- a/samples/client/petstore/go/go-petstore/docs/StoreApi.md +++ b/samples/client/petstore/go/go-petstore/docs/StoreApi.md @@ -48,7 +48,7 @@ This endpoint does not need any parameter. ### Return type -[**map[string]int32**](map.md) +**map[string]int32** ### Authorization diff --git a/samples/client/petstore/go/go-petstore/fake_classname_tags123_api.go b/samples/client/petstore/go/go-petstore/fake_classname_tags123_api.go index 1154155250c..82a24af48b9 100644 --- a/samples/client/petstore/go/go-petstore/fake_classname_tags123_api.go +++ b/samples/client/petstore/go/go-petstore/fake_classname_tags123_api.go @@ -23,14 +23,14 @@ var ( _ context.Context ) -type Fake_classname_tags123ApiService service +type FakeClassnameTags123ApiService service -/* Fake_classname_tags123ApiService To test class name in snake case - +/* FakeClassnameTags123ApiService To test class name in snake case + * @param ctx context.Context Authentication Context @param body client model @return Client*/ -func (a *Fake_classname_tags123ApiService) TestClassname(body Client) (Client, *http.Response, error) { +func (a *FakeClassnameTags123ApiService) TestClassname(ctx context.Context, body Client) (Client, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Patch") localVarPostBody interface{} @@ -68,7 +68,19 @@ func (a *Fake_classname_tags123ApiService) TestClassname(body Client) (Client, } // body params localVarPostBody = &body - r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarQueryParams.Add("api_key_query", key) + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) if err != nil { return successPayload, nil, err }