mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
updated function to support multiple collection formats
This commit is contained in:
parent
0bc34dcae8
commit
e7f68287c1
@ -86,11 +86,11 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{
|
||||
queryParams.Add("{{paramName}}", value)
|
||||
}
|
||||
} else {
|
||||
queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}}))
|
||||
queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, collectionFormat))
|
||||
}
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}}))
|
||||
queryParams.Add("{{paramName}}", a.Configuration.APIClient.ParameterToString({{paramName}}, ""))
|
||||
{{/isListContainer}}
|
||||
{{/queryParams}}{{/hasQueryParams}}
|
||||
|
||||
|
@ -79,12 +79,21 @@ func (c *APIClient) CallAPI(path string, method string,
|
||||
return nil, fmt.Errorf("invalid method %v", method)
|
||||
}
|
||||
|
||||
func (c *APIClient) ParameterToString(obj interface{}) string {
|
||||
func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) string {
|
||||
if reflect.TypeOf(obj).String() == "[]string" {
|
||||
return strings.Join(obj.([]string), ",")
|
||||
} else {
|
||||
return obj.(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), ",")
|
||||
}
|
||||
}
|
||||
|
||||
return obj.(string)
|
||||
}
|
||||
|
||||
func prepareRequest(postBody interface{},
|
||||
|
@ -79,12 +79,21 @@ func (c *APIClient) CallAPI(path string, method string,
|
||||
return nil, fmt.Errorf("invalid method %v", method)
|
||||
}
|
||||
|
||||
func (c *APIClient) ParameterToString(obj interface{}) string {
|
||||
func (c *APIClient) ParameterToString(obj interface{},collectionFormat string) string {
|
||||
if reflect.TypeOf(obj).String() == "[]string" {
|
||||
return strings.Join(obj.([]string), ",")
|
||||
} else {
|
||||
return obj.(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), ",")
|
||||
}
|
||||
}
|
||||
|
||||
return obj.(string)
|
||||
}
|
||||
|
||||
func prepareRequest(postBody interface{},
|
||||
|
@ -207,7 +207,7 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) {
|
||||
queryParams.Add("status", value)
|
||||
}
|
||||
} else {
|
||||
queryParams.Add("status", a.Configuration.APIClient.ParameterToString(status))
|
||||
queryParams.Add("status", a.Configuration.APIClient.ParameterToString(status, collectionFormat))
|
||||
}
|
||||
|
||||
|
||||
@ -279,7 +279,7 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) {
|
||||
queryParams.Add("tags", value)
|
||||
}
|
||||
} else {
|
||||
queryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags))
|
||||
queryParams.Add("tags", a.Configuration.APIClient.ParameterToString(tags, collectionFormat))
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,8 +368,8 @@ func (a UserApi) LoginUser(username string, password string) (*string, *APIRespo
|
||||
for key := range a.Configuration.DefaultHeader {
|
||||
headerParams[key] = a.Configuration.DefaultHeader[key]
|
||||
}
|
||||
queryParams.Add("username", a.Configuration.APIClient.ParameterToString(username))
|
||||
queryParams.Add("password", a.Configuration.APIClient.ParameterToString(password))
|
||||
queryParams.Add("username", a.Configuration.APIClient.ParameterToString(username, ""))
|
||||
queryParams.Add("password", a.Configuration.APIClient.ParameterToString(password, ""))
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
|
Loading…
Reference in New Issue
Block a user