forked from loafle/openapi-generator-original
Remove invalid code from mustache for arrays. (#4266)
Rewrite ParameterToString to handle other slice types other than just string.
This commit is contained in:
parent
5818f2c882
commit
e55664cdc9
@ -83,13 +83,8 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
|
|||||||
{{#queryParams}}
|
{{#queryParams}}
|
||||||
{{#isListContainer}}
|
{{#isListContainer}}
|
||||||
var collectionFormat = "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"
|
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}}
|
||||||
{{^isListContainer}}
|
{{^isListContainer}}
|
||||||
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, ""))
|
localVarQueryParams.Add("{{baseName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, ""))
|
||||||
|
@ -80,17 +80,20 @@ func (c *APIClient) CallAPI(path string, method string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string {
|
func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string {
|
||||||
if reflect.TypeOf(obj).String() == "[]string" {
|
delimiter := ""
|
||||||
switch collectionFormat {
|
switch collectionFormat {
|
||||||
case "pipes":
|
case "pipes":
|
||||||
return strings.Join(obj.([]string), "|")
|
delimiter = "|"
|
||||||
case "ssv":
|
case "ssv":
|
||||||
return strings.Join(obj.([]string), " ")
|
delimiter = " "
|
||||||
case "tsv":
|
case "tsv":
|
||||||
return strings.Join(obj.([]string), "\t")
|
delimiter = "\t"
|
||||||
case "csv":
|
case "csv":
|
||||||
return strings.Join(obj.([]string), ",")
|
delimiter = ","
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if reflect.TypeOf(obj).Kind() == reflect.Slice {
|
||||||
|
return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%v", obj)
|
return fmt.Sprintf("%v", obj)
|
||||||
|
@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [ArrayTest](docs/ArrayTest.md)
|
- [ArrayTest](docs/ArrayTest.md)
|
||||||
- [Cat](docs/Cat.md)
|
- [Cat](docs/Cat.md)
|
||||||
- [Category](docs/Category.md)
|
- [Category](docs/Category.md)
|
||||||
|
- [ClassModel](docs/ClassModel.md)
|
||||||
- [Client](docs/Client.md)
|
- [Client](docs/Client.md)
|
||||||
- [Dog](docs/Dog.md)
|
- [Dog](docs/Dog.md)
|
||||||
- [EnumArrays](docs/EnumArrays.md)
|
- [EnumArrays](docs/EnumArrays.md)
|
||||||
@ -72,6 +73,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [Name](docs/Name.md)
|
- [Name](docs/Name.md)
|
||||||
- [NumberOnly](docs/NumberOnly.md)
|
- [NumberOnly](docs/NumberOnly.md)
|
||||||
- [Order](docs/Order.md)
|
- [Order](docs/Order.md)
|
||||||
|
- [OuterEnum](docs/OuterEnum.md)
|
||||||
- [Pet](docs/Pet.md)
|
- [Pet](docs/Pet.md)
|
||||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||||
- [SpecialModelName](docs/SpecialModelName.md)
|
- [SpecialModelName](docs/SpecialModelName.md)
|
||||||
|
@ -89,17 +89,20 @@ func (c *APIClient) CallAPI(path string, method string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string {
|
func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string {
|
||||||
if reflect.TypeOf(obj).String() == "[]string" {
|
delimiter := ""
|
||||||
switch collectionFormat {
|
switch collectionFormat {
|
||||||
case "pipes":
|
case "pipes":
|
||||||
return strings.Join(obj.([]string), "|")
|
delimiter = "|"
|
||||||
case "ssv":
|
case "ssv":
|
||||||
return strings.Join(obj.([]string), " ")
|
delimiter = " "
|
||||||
case "tsv":
|
case "tsv":
|
||||||
return strings.Join(obj.([]string), "\t")
|
delimiter = "\t"
|
||||||
case "csv":
|
case "csv":
|
||||||
return strings.Join(obj.([]string), ",")
|
delimiter = ","
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if reflect.TypeOf(obj).Kind() == reflect.Slice {
|
||||||
|
return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%v", obj)
|
return fmt.Sprintf("%v", obj)
|
||||||
|
17
samples/client/petstore/go/go-petstore/class_model.go
Normal file
17
samples/client/petstore/go/go-petstore/class_model.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
// Model for testing model with \"_class\" property
|
||||||
|
type ClassModel struct {
|
||||||
|
|
||||||
|
Class string `json:"_class,omitempty"`
|
||||||
|
}
|
10
samples/client/petstore/go/go-petstore/docs/ClassModel.md
Normal file
10
samples/client/petstore/go/go-petstore/docs/ClassModel.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# ClassModel
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**Class** | **string** | | [optional] [default to null]
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -6,6 +6,7 @@ Name | Type | Description | Notes
|
|||||||
**EnumString** | **string** | | [optional] [default to null]
|
**EnumString** | **string** | | [optional] [default to null]
|
||||||
**EnumInteger** | **int32** | | [optional] [default to null]
|
**EnumInteger** | **int32** | | [optional] [default to null]
|
||||||
**EnumNumber** | **float64** | | [optional] [default to null]
|
**EnumNumber** | **float64** | | [optional] [default to null]
|
||||||
|
**OuterEnum** | [**OuterEnum**](OuterEnum.md) | | [optional] [default to null]
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# \FakeApi
|
# \FakeApi
|
||||||
|
|
||||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
All URIs are relative to **
|
||||||
|
|
||||||
Method | HTTP request | Description
|
Method | HTTP request | Description
|
||||||
------------- | ------------- | -------------
|
------------- | ------------- | -------------
|
||||||
|
9
samples/client/petstore/go/go-petstore/docs/OuterEnum.md
Normal file
9
samples/client/petstore/go/go-petstore/docs/OuterEnum.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# OuterEnum
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
# \PetApi
|
# \PetApi
|
||||||
|
|
||||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
All URIs are relative to **
|
||||||
|
|
||||||
Method | HTTP request | Description
|
Method | HTTP request | Description
|
||||||
------------- | ------------- | -------------
|
------------- | ------------- | -------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# \StoreApi
|
# \StoreApi
|
||||||
|
|
||||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
All URIs are relative to **
|
||||||
|
|
||||||
Method | HTTP request | Description
|
Method | HTTP request | Description
|
||||||
------------- | ------------- | -------------
|
------------- | ------------- | -------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# \UserApi
|
# \UserApi
|
||||||
|
|
||||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
All URIs are relative to **
|
||||||
|
|
||||||
Method | HTTP request | Description
|
Method | HTTP request | Description
|
||||||
------------- | ------------- | -------------
|
------------- | ------------- | -------------
|
||||||
|
@ -17,4 +17,6 @@ type EnumTest struct {
|
|||||||
EnumInteger int32 `json:"enum_integer,omitempty"`
|
EnumInteger int32 `json:"enum_integer,omitempty"`
|
||||||
|
|
||||||
EnumNumber float64 `json:"enum_number,omitempty"`
|
EnumNumber float64 `json:"enum_number,omitempty"`
|
||||||
|
|
||||||
|
OuterEnum OuterEnum `json:"outerEnum,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -219,13 +219,8 @@ func (a FakeApi) TestEnumParameters(enumFormStringArray []string, enumFormString
|
|||||||
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
||||||
}
|
}
|
||||||
var collectionFormat = "csv"
|
var collectionFormat = "csv"
|
||||||
if collectionFormat == "multi" {
|
|
||||||
for _, value := range enumQueryStringArray {
|
|
||||||
localVarQueryParams.Add("enum_query_string_array", value)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localVarQueryParams.Add("enum_query_string_array", a.Configuration.APIClient.ParameterToString(enumQueryStringArray, collectionFormat))
|
localVarQueryParams.Add("enum_query_string_array", a.Configuration.APIClient.ParameterToString(enumQueryStringArray, collectionFormat))
|
||||||
}
|
|
||||||
localVarQueryParams.Add("enum_query_string", a.Configuration.APIClient.ParameterToString(enumQueryString, ""))
|
localVarQueryParams.Add("enum_query_string", a.Configuration.APIClient.ParameterToString(enumQueryString, ""))
|
||||||
localVarQueryParams.Add("enum_query_integer", a.Configuration.APIClient.ParameterToString(enumQueryInteger, ""))
|
localVarQueryParams.Add("enum_query_integer", a.Configuration.APIClient.ParameterToString(enumQueryInteger, ""))
|
||||||
|
|
||||||
|
14
samples/client/petstore/go/go-petstore/outer_enum.go
Normal file
14
samples/client/petstore/go/go-petstore/outer_enum.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
type OuterEnum struct {
|
||||||
|
}
|
@ -202,13 +202,8 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) {
|
|||||||
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
||||||
}
|
}
|
||||||
var collectionFormat = "csv"
|
var collectionFormat = "csv"
|
||||||
if collectionFormat == "multi" {
|
|
||||||
for _, value := range status {
|
|
||||||
localVarQueryParams.Add("status", value)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localVarQueryParams.Add("status", a.Configuration.APIClient.ParameterToString(status, collectionFormat))
|
localVarQueryParams.Add("status", a.Configuration.APIClient.ParameterToString(status, collectionFormat))
|
||||||
}
|
|
||||||
|
|
||||||
// to determine the Content-Type header
|
// to determine the Content-Type header
|
||||||
localVarHttpContentTypes := []string{ }
|
localVarHttpContentTypes := []string{ }
|
||||||
@ -276,13 +271,8 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) {
|
|||||||
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
||||||
}
|
}
|
||||||
var collectionFormat = "csv"
|
var collectionFormat = "csv"
|
||||||
if collectionFormat == "multi" {
|
|
||||||
for _, value := range tags {
|
|
||||||
localVarQueryParams.Add("tags", value)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localVarQueryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags, collectionFormat))
|
localVarQueryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags, collectionFormat))
|
||||||
}
|
|
||||||
|
|
||||||
// to determine the Content-Type header
|
// to determine the Content-Type header
|
||||||
localVarHttpContentTypes := []string{ }
|
localVarHttpContentTypes := []string{ }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user