Skip to content

Commit d0848b1

Browse files
author
Balakrishnan Ranganathan
committed
Support for collections in query strings
1 parent 0410aae commit d0848b1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/WebApiToTypeScript/WebApiToTypeScript.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,24 @@ private void CreateQueryStringBlock(TypeScriptBlock classBlock, WebApiAction act
188188

189189
if (argumentType.IsPrimitive || argumentType.IsEnum)
190190
{
191-
block
192-
.AddStatement($"parameters.push(`{argumentName}=${{this.{argumentName}}}`);");
191+
if (argumentType.IsCollection)
192+
{
193+
block
194+
.AddStatement($"parameters.push(`{argumentName}=${{this.{argumentName}.join(',')}}`);");
195+
}
196+
else
197+
{
198+
block
199+
.AddStatement($"parameters.push(`{argumentName}=${{encodeURIComponent(this.{argumentName}.toString())}}`);");
200+
}
193201
}
194202
else
195203
{
196204
block
197205
.AddStatement($"let {argumentName}Params = this.{argumentName}.getQueryParams();")
198206
.AddAndUseBlock($"Object.keys({argumentName}Params).forEach((key) =>", isFunctionBlock: true, terminateWithSemicolon: true)
199207
.AddAndUseBlock($"if ({argumentName}Params[key] != null)")
200-
.AddStatement($"parameters.push(`${{key}}=${{encodeURIComponent({argumentName}Params[key])}}`);");
208+
.AddStatement($"parameters.push(`${{key}}=${{encodeURIComponent({argumentName}Params[key].toString())}}`);");
201209
}
202210
}
203211

0 commit comments

Comments
 (0)