updated function to support multiple collection formats

This commit is contained in:
Guo Huang 2016-05-09 22:01:32 -07:00
parent 0bc34dcae8
commit e7f68287c1
5 changed files with 32 additions and 14 deletions

View File

@ -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}}

View File

@ -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{},

View File

@ -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{},

View File

@ -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))
}

View File

@ -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