forked from loafle/openapi-generator-original
[GO CLIENT] Fix issue with generating code for API key (#6630)
* [GO CLIENT] Fix Go security query parameter generation by using correct string literal and using the Add method. * Add generated files.
This commit is contained in:
parent
42313af7a1
commit
567ae3fd12
@ -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}}
|
||||
|
@ -0,0 +1 @@
|
||||
2.3.0-SNAPSHOT
|
@ -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)
|
||||
|
@ -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{
|
||||
|
93
samples/client/petstore/go/go-petstore/another_fake_api.go
Normal file
93
samples/client/petstore/go/go-petstore/another_fake_api.go
Normal file
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -48,7 +48,7 @@ This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
[**map[string]int32**](map.md)
|
||||
**map[string]int32**
|
||||
|
||||
### Authorization
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user