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,16 +83,11 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
|
||||
{{#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))
|
||||
}
|
||||
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}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
|
@ -79,18 +79,21 @@ 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)
|
||||
|
@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
|
||||
- [ArrayTest](docs/ArrayTest.md)
|
||||
- [Cat](docs/Cat.md)
|
||||
- [Category](docs/Category.md)
|
||||
- [ClassModel](docs/ClassModel.md)
|
||||
- [Client](docs/Client.md)
|
||||
- [Dog](docs/Dog.md)
|
||||
- [EnumArrays](docs/EnumArrays.md)
|
||||
@ -72,6 +73,7 @@ Class | Method | HTTP request | Description
|
||||
- [Name](docs/Name.md)
|
||||
- [NumberOnly](docs/NumberOnly.md)
|
||||
- [Order](docs/Order.md)
|
||||
- [OuterEnum](docs/OuterEnum.md)
|
||||
- [Pet](docs/Pet.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
- [SpecialModelName](docs/SpecialModelName.md)
|
||||
|
@ -88,18 +88,21 @@ 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)
|
||||
|
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]
|
||||
**EnumInteger** | **int32** | | [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)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# \FakeApi
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
All URIs are relative to **
|
||||
|
||||
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
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
All URIs are relative to **
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
|
@ -1,6 +1,6 @@
|
||||
# \StoreApi
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
All URIs are relative to **
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
|
@ -1,6 +1,6 @@
|
||||
# \UserApi
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
All URIs are relative to **
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
|
@ -17,4 +17,6 @@ type EnumTest struct {
|
||||
EnumInteger int32 `json:"enum_integer,omitempty"`
|
||||
|
||||
EnumNumber float64 `json:"enum_number,omitempty"`
|
||||
|
||||
OuterEnum OuterEnum `json:"outerEnum,omitempty"`
|
||||
}
|
||||
|
@ -219,15 +219,10 @@ func (a FakeApi) TestEnumParameters(enumFormStringArray []string, enumFormString
|
||||
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
||||
}
|
||||
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", a.Configuration.APIClient.ParameterToString(enumQueryString, ""))
|
||||
localVarQueryParams.Add("enum_query_integer", a.Configuration.APIClient.ParameterToString(enumQueryInteger, ""))
|
||||
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_integer", a.Configuration.APIClient.ParameterToString(enumQueryInteger, ""))
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string{ "*/*", }
|
||||
|
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]
|
||||
}
|
||||
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
|
||||
localVarHttpContentTypes := []string{ }
|
||||
@ -276,13 +271,8 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) {
|
||||
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
||||
}
|
||||
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
|
||||
localVarHttpContentTypes := []string{ }
|
||||
|
@ -366,8 +366,8 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo
|
||||
for key := range a.Configuration.DefaultHeader {
|
||||
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
|
||||
}
|
||||
localVarQueryParams.Add("username", a.Configuration.APIClient.ParameterToString(username, ""))
|
||||
localVarQueryParams.Add("password", a.Configuration.APIClient.ParameterToString(password, ""))
|
||||
localVarQueryParams.Add("username", a.Configuration.APIClient.ParameterToString(username, ""))
|
||||
localVarQueryParams.Add("password", a.Configuration.APIClient.ParameterToString(password, ""))
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string{ }
|
||||
|
Loading…
x
Reference in New Issue
Block a user