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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
*.iml
out/
*.ipr
Expand Down
68 changes: 46 additions & 22 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,12 @@ 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}}{{#required}} * @param {{paramName}} {{description}}
{{/required}}{{/allParams}}{{#hasOptionalParams}} * @param optional (nil or map[string]interface{}) with one or more of:
{{#allParams}}{{^required}} * @param "{{paramName}}" ({{dataType}}) {{description}}
{{/required}}{{/allParams}}{{/hasOptionalParams}} * @return {{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}{{/returnType}}
*/
func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}, {{/returnType}}*APIResponse, error) {
func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals map[string]interface{}{{/hasOptionalParams}}) ({{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}, {{/returnType}}*APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
// create path and map variables
Expand Down Expand Up @@ -81,19 +83,14 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
}
{{#hasQueryParams}}
{{#queryParams}}
{{#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))
{{#required}}
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
{{/required}}
{{^required}}
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOptionals != nil && localVarOk {
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString(localVarTempParam, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
}
{{/isListContainer}}
{{^isListContainer}}
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, ""))
{{/isListContainer}}
{{/required}}
{{/queryParams}}
{{/hasQueryParams}}

Expand All @@ -119,25 +116,52 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
}
{{#hasHeaderParams}}
{{#headerParams}}
// header params "{{baseName}}"
localVarHeaderParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "")
{{#required}}
localVarHeaderParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
{{/required}}
{{^required}}
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOptionals != nil && localVarOk {
localVarHeaderParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString(localVarTempParam, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
}
{{/required}}
{{/headerParams}}
{{/hasHeaderParams}}
{{#hasFormParams}}
{{#formParams}}
{{#isFile}}
fbs, _ := ioutil.ReadAll(file)
localVarFileBytes = fbs
localVarFileName = file.Name()
{{^required}}
var file ({{dataType}})
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOptionals != nil && localVarOk {
file = localVarTempParam
}
{{/required}}
if file != nil {
fbs, _ := ioutil.ReadAll(file)
localVarFileBytes = fbs
localVarFileName = file.Name()
}
{{/isFile}}
{{^isFile}}
localVarFormParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "")
{{#required}}
localVarFormParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
{{/required}}
{{^required}}
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOptionals != nil && localVarOk {
localVarFormParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString(localVarTempParam, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
}
{{/required}}
{{/isFile}}
{{/formParams}}
{{/hasFormParams}}
{{#hasBodyParam}}
{{#bodyParams}} // body params
localVarPostBody = &{{paramName}}
{{#required}}
localVarPostBody = &{{paramName}}{{/required}}
{{^required}}
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOptionals != nil && localVarOk {
localVarPostBody = &localVarTempParam
}
{{/required}}
{{/bodyParams}}
{{/hasBodyParam}}
{{#returnType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{/allParams}}
{{#hasOptionalParams}}

Note: Optional parameters are passed through a map[string]interface{}
{{/hasOptionalParams}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do it one step further by providing code samples similar to what we've done for other languages (e.g. C#, Python, etc)

### Return type

{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}
{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}(empty response body){{/returnType}}

### Authorization

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
15 changes: 10 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 @@ -61,10 +61,13 @@ Name | Type | Description | Notes
**date** | **time.Time**| None | [optional]
**dateTime** | **time.Time**| None | [optional]
**password** | **string**| None | [optional]
**callback** | **string**| None | [optional]

Note: Optional parameters are passed through a map[string]interface{}

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -96,18 +99,20 @@ Name | Type | Description | Notes
**enumQueryInteger** | **float32**| Query parameter enum test (double) | [optional]
**enumQueryDouble** | **float64**| Query parameter enum test (double) | [optional]

Note: Optional parameters are passed through a map[string]interface{}

### Return type

void (empty response body)
(empty response body)

### Authorization

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)

14 changes: 10 additions & 4 deletions samples/client/petstore/go/go-petstore/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -58,9 +58,11 @@ Name | Type | Description | Notes
**petId** | **int64**| Pet id to delete |
**apiKey** | **string**| | [optional]

Note: Optional parameters are passed through a map[string]interface{}

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -176,7 +178,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -205,9 +207,11 @@ Name | Type | Description | Notes
**name** | **string**| Updated name of the pet | [optional]
**status** | **string**| Updated status of the pet | [optional]

Note: Optional parameters are passed through a map[string]interface{}

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -236,6 +240,8 @@ Name | Type | Description | Notes
**additionalMetadata** | **string**| Additional data to pass to server | [optional]
**file** | ***os.File**| file to upload | [optional]

Note: Optional parameters are passed through a map[string]interface{}

### Return type

[**ModelApiResponse**](ApiResponse.md)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/go/go-petstore/docs/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -59,7 +59,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -88,7 +88,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -117,7 +117,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -202,7 +202,7 @@ This endpoint does not need any parameter.

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down Expand Up @@ -232,7 +232,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
(empty response body)

### Authorization

Expand Down
Loading