Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ public void postProcessParameter(CodegenParameter parameter){
StringBuilder sb = new StringBuilder(parameter.paramName);
sb.setCharAt(0, Character.toUpperCase(firstChar));
parameter.vendorExtensions.put("x-exportParamName", sb.toString());

// Dates are not a primitive. Not sure how this is getting flagged as such.
if (parameter.isDate != null|| parameter.isDateTime != null || parameter.isFile != null) {
parameter.isPrimitiveType = Boolean.FALSE;
}
}


Expand Down
37 changes: 23 additions & 14 deletions modules/swagger-codegen/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}} {
* {{summary}}{{#notes}}
* {{notes}}{{/notes}}
*
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
{{#allParams}} * @param {{paramName}}{{^required}}{{#isPrimitiveType}}(nil){{/isPrimitiveType}}{{/required}} {{description}}
{{/allParams}} * @return {{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}
*/
func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}, {{/returnType}}*APIResponse, error) {
func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{#required}}{{{dataType}}}{{/required}}{{^required}}{{#isPrimitiveType}}interface{}{{/isPrimitiveType}}{{^isPrimitiveType}}{{{dataType}}}{{/isPrimitiveType}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}, {{/returnType}}*APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
// create path and map variables
Expand Down Expand Up @@ -79,21 +79,30 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}

{{#allParams}}
{{^required}}
{{#isPrimitiveType}}
if err := a.Configuration.APIClient.typeCheckParameter({{paramName}}, "{{{dataType}}}", "{{paramName}}"); err != nil {
return {{#returnType}}nil, {{/returnType}} nil, err
}
{{/isPrimitiveType}}
{{/required}}
{{/allParams}}
{{#hasQueryParams}}
{{#queryParams}}
{{^required}}
if {{paramName}} != nil {
{{/required}}
{{#isListContainer}}
var collectionFormat = "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"
if collectionFormat == "multi" {
for _, value := range {{paramName}} {
localVarQueryParams.Add("{{baseName}}", value)
}
} else {
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, collectionFormat))
}
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.parameterToString({{paramName}}, "{{collectionFormat}}"))
{{/isListContainer}}
{{^isListContainer}}
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, ""))
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.parameterToString({{paramName}}, ""))
{{/isListContainer}}
{{^required}}
}
{{/required}}
{{/queryParams}}
{{/hasQueryParams}}

Expand All @@ -120,7 +129,7 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
{{#hasHeaderParams}}
{{#headerParams}}
// header params "{{baseName}}"
localVarHeaderParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "")
localVarHeaderParams["{{baseName}}"] = a.Configuration.APIClient.parameterToString({{paramName}}, "")
{{/headerParams}}
{{/hasHeaderParams}}
{{#hasFormParams}}
Expand All @@ -131,7 +140,7 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
localVarFileName = file.Name()
{{/isFile}}
{{^isFile}}
localVarFormParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "")
localVarFormParams["{{paramName}}"] = a.Configuration.APIClient.parameterToString({{paramName}}, "")
{{/isFile}}
{{/formParams}}
{{/hasFormParams}}
Expand Down
41 changes: 29 additions & 12 deletions modules/swagger-codegen/src/main/resources/go/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strings"
"net/url"
"errors"
"io/ioutil"
"github.com/go-resty/resty"
)
Expand Down Expand Up @@ -79,22 +80,38 @@ func (c *APIClient) CallAPI(path string, method string,
return nil, fmt.Errorf("invalid method %v", method)
}

func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) string {
if reflect.TypeOf(obj).String() == "[]string" {
switch collectionFormat {
case "pipes":
return strings.Join(obj.([]string), "|")
case "ssv":
return strings.Join(obj.([]string), " ")
case "tsv":
return strings.Join(obj.([]string), "\t")
case "csv" :
return strings.Join(obj.([]string), ",")
}
func (c *APIClient) parameterToString(obj interface{}, collectionFormat string) string {
delimiter := ""
switch collectionFormat {
case "pipes":
delimiter = "|"
case "ssv":
delimiter = " "
case "tsv":
delimiter = "\t"
case "csv":
delimiter = ","
}

if reflect.TypeOf(obj).Kind() == reflect.Slice {
return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]")
}

return fmt.Sprintf("%v", obj)
}
// Verify optional parameters are of the correct type.
func (c *APIClient) typeCheckParameter(obj interface{}, expected string, name string) error {
// Make sure there is an object.
if obj == nil {
return nil
}

// Check the type is as expected.
if reflect.TypeOf(obj).String() != expected {
return errors.New(fmt.Sprintf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()))
}
return nil
}

func (c *APIClient) prepareClient() *resty.Client {

Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **Patch** /fake | To test \"client\" model
*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
*Fake_classname_tags123Api* | [**TestClassname**](docs/Fake_classname_tags123Api.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
Expand Down
44 changes: 30 additions & 14 deletions samples/client/petstore/go/go-petstore/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"reflect"
"strings"
"net/url"
"io/ioutil"
"errors"
"github.com/go-resty/resty"
)

Expand Down Expand Up @@ -100,22 +100,38 @@ func (c *APIClient) CallAPI(path string, method string,
return nil, fmt.Errorf("invalid method %v", method)
}

func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) string {
if reflect.TypeOf(obj).String() == "[]string" {
switch collectionFormat {
case "pipes":
return strings.Join(obj.([]string), "|")
case "ssv":
return strings.Join(obj.([]string), " ")
case "tsv":
return strings.Join(obj.([]string), "\t")
case "csv" :
return strings.Join(obj.([]string), ",")
}
func (c *APIClient) parameterToString(obj interface{}, collectionFormat string) string {
delimiter := ""
switch collectionFormat {
case "pipes":
delimiter = "|"
case "ssv":
delimiter = " "
case "tsv":
delimiter = "\t"
case "csv":
delimiter = ","
}

if reflect.TypeOf(obj).Kind() == reflect.Slice {
return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]")
}

return fmt.Sprintf("%v", obj)
}
// Verify optional parameters are of the correct type.
func (c *APIClient) typeCheckParameter(obj interface{}, expected string, name string) error {
// Make sure there is an object.
if obj == nil {
return nil
}

// Check the type is as expected.
if reflect.TypeOf(obj).String() != expected {
return errors.New(fmt.Sprintf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()))
}
return nil
}

func (c *APIClient) prepareClient() *resty.Client {

Expand All @@ -129,7 +145,7 @@ func (c *APIClient) prepareClient() *resty.Client {
if c.config.Timeout != nil {
rClient.SetTimeout(*c.config.Timeout)
}
rClient.SetLogger(ioutil.Discard)

return rClient
}

Expand Down
11 changes: 6 additions & 5 deletions samples/client/petstore/go/go-petstore/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ No authorization required
[[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)

# **TestEndpointParameters**
> TestEndpointParameters($number, $double, $patternWithoutDelimiter, $byte_, $integer, $int32_, $int64_, $float, $string_, $binary, $date, $dateTime, $password)
> TestEndpointParameters($number, $double, $patternWithoutDelimiter, $byte_, $integer, $int32_, $int64_, $float, $string_, $binary, $date, $dateTime, $password, $callback)

Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트

Expand All @@ -58,9 +58,10 @@ Name | Type | Description | Notes
**float** | **float32**| None | [optional]
**string_** | **string**| None | [optional]
**binary** | **string**| None | [optional]
**date** | **time.Time**| None | [optional]
**dateTime** | **time.Time**| None | [optional]
**date** | [**time.Time**](.md)| None | [optional]
**dateTime** | [**time.Time**](.md)| None | [optional]
**password** | **string**| None | [optional]
**callback** | **string**| None | [optional]

### Return type

Expand Down Expand Up @@ -106,8 +107,8 @@ No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json
- **Content-Type**: */*
- **Accept**: */*

[[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)

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# \Fake_classname_tags123Api

All URIs are relative to *http://petstore.swagger.io/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**TestClassname**](Fake_classname_tags123Api.md#TestClassname) | **Patch** /fake_classname_test | To test class name in snake case


# **TestClassname**
> Client TestClassname($body)

To test class name in snake case


### 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)

Loading