Skip to content

Commit 9c747e3

Browse files
committed
fix query parameters
1 parent 5f36ad3 commit 9c747e3

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace {{invokerPackage}} {
5353
5454
// add query parameter, if any
5555
foreach(KeyValuePair<string, string> param in QueryParams)
56-
request.AddUrlSegment(param.Key, param.Value);
56+
request.AddQueryParameter(param.Key, param.Value);
5757
5858
// add form parameter, if any
5959
foreach(KeyValuePair<string, string> param in FormParams)
@@ -99,13 +99,21 @@ namespace {{invokerPackage}} {
9999
}
100100

101101
/// <summary>
102-
/// if parameter is DateTime, output in ISO8601 format, otherwise just return the string
102+
/// if parameter is DateTime, output in ISO8601 format
103+
/// if parameter is a list of string, join the list with ","
104+
/// otherwise just return the string
103105
/// </summary>
104106
/// <param name="obj"> The parameter (header, path, query, form)
105107
/// <returns>Formatted string</returns>
106108
public string ParameterToString(object obj)
107109
{
108-
return (obj is DateTime) ? ((DateTime)obj).ToString ("u") : Convert.ToString (obj);
110+
if (obj is DateTime) {
111+
return ((DateTime)obj).ToString ("u");
112+
} else if (obj is List<string>) {
113+
return String.Join(",", obj as List<string>);
114+
} else {
115+
return Convert.ToString (obj);
116+
}
109117
}
110118

111119
/// <summary>

samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiClient.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, S
5353

5454
// add query parameter, if any
5555
foreach(KeyValuePair<string, string> param in QueryParams)
56-
request.AddUrlSegment(param.Key, param.Value);
56+
request.AddQueryParameter(param.Key, param.Value);
5757

5858
// add form parameter, if any
5959
foreach(KeyValuePair<string, string> param in FormParams)
@@ -99,13 +99,21 @@ public string EscapeString(string str) {
9999
}
100100

101101
/// <summary>
102-
/// if parameter is DateTime, output in ISO8601 format, otherwise just return the string
102+
/// if parameter is DateTime, output in ISO8601 format
103+
/// if parameter is a list of string, join the list with ","
104+
/// otherwise just return the string
103105
/// </summary>
104106
/// <param name="obj"> The parameter (header, path, query, form)
105107
/// <returns>Formatted string</returns>
106108
public string ParameterToString(object obj)
107109
{
108-
return (obj is DateTime) ? ((DateTime)obj).ToString ("u") : Convert.ToString (obj);
110+
if (obj is DateTime) {
111+
return ((DateTime)obj).ToString ("u");
112+
} else if (obj is List<string>) {
113+
return String.Join(",", obj as List<string>);
114+
} else {
115+
return Convert.ToString (obj);
116+
}
109117
}
110118

111119
/// <summary>

0 commit comments

Comments
 (0)