Skip to content

Commit 5d6c563

Browse files
author
James Brundage
committed
[REST] Updates: Fixing #118
1 parent f24d9d6 commit 5d6c563

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

Transpilers/Rest.psx.ps1

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,28 @@ process {
350350
}
351351
{
352352
process {
353+
foreach ($qp in @($QueryParams.GetEnumerator())) {
354+
$qpValue =
355+
if ($qp.Value -is [DateTime]) {
356+
$qp.Value.Tostring('o')
357+
}
358+
elseif ($qp.Value -is [switch]) {
359+
$qp.Value -as [bool]
360+
}
361+
else {
362+
$qp.Value
363+
}
364+
365+
$queryParams[$qp.Key] = $qpValue
366+
}
367+
353368
if ($invokerCommandinfo.Parameters['QueryParameter'] -and
354369
$invokerCommandinfo.Parameters['QueryParameter'].ParameterType -eq [Collections.IDictionary]) {
355-
$invokerCommandinfo.QueryParameter = $QueryParams
370+
$invokeSplat.QueryParameter = $QueryParams
356371
} else {
357372
$queryParamStr =
358373
@(foreach ($qp in $QueryParams.GetEnumerator()) {
359-
"$($qp.Key)=$([Web.HttpUtility]::UrlEncode($qp.Value).Replace('+', '%20'))"
374+
"$($qp.Key)=$([Web.HttpUtility]::UrlEncode($qpValue).Replace('+', '%20'))"
360375
}) -join '&'
361376
if ($invokeSplat.Uri.Contains('?')) {
362377
$invokeSplat.Uri = "$($invokeSplat.Uri)" + '&' + $queryParamStr
@@ -384,6 +399,21 @@ process {
384399
}
385400
}
386401

402+
foreach ($bodyPart in @($completeBody.GetEnumerator())) {
403+
$bodyValue =
404+
if ($bodyPart.Value -is [DateTime]) {
405+
$bodyPart.Value.ToString('o')
406+
}
407+
elseif ($bodyPart.Value -is [switch]) {
408+
$bodyPart.Value -as [bool]
409+
}
410+
else {
411+
$bodyPart.Value
412+
}
413+
414+
$completeBody[$bodyPart.Key] = $bodyValue
415+
}
416+
387417
$bodyContent =
388418
if ($ContentType -match 'x-www-form-urlencoded') {
389419
@(foreach ($bodyPart in $completeBody.GetEnumerator()) {

0 commit comments

Comments
 (0)