From 9d14a73ca51d1292857db9e647b0eefe48c66d98 Mon Sep 17 00:00:00 2001 From: condorcorde Date: Tue, 23 Jul 2024 10:58:12 +0200 Subject: [PATCH] Conditionally force array context when converting to JSON --- .../src/main/resources/powershell/api.mustache | 5 +++++ .../petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell/api.mustache b/modules/openapi-generator/src/main/resources/powershell/api.mustache index c13395de842c..d648594aeb43 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api.mustache @@ -172,7 +172,12 @@ function {{{vendorExtensions.x-powershell-method-name}}} { {{/isNullable}} {{/required}} + {{#isArray}} + $LocalVarBodyParameter = ,${{{paramName}}} | ConvertTo-Json -Depth 100 + {{/isArray}} + {{^isArray}} $LocalVarBodyParameter = ${{{paramName}}} | ConvertTo-Json -Depth 100 + {{/isArray}} {{/bodyParam}} {{#authMethods}} diff --git a/samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 index 6d3be8f1037e..d1a485d31e29 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 @@ -133,7 +133,7 @@ function New-PSUsersWithArrayInput { throw "Error! The required parameter `User` missing when calling createUsersWithArrayInput." } - $LocalVarBodyParameter = $User | ConvertTo-Json -Depth 100 + $LocalVarBodyParameter = ,$User | ConvertTo-Json -Depth 100 $LocalVarResult = Invoke-PSApiClient -Method 'POST' ` -Uri $LocalVarUri ` @@ -208,7 +208,7 @@ function New-PSUsersWithListInput { throw "Error! The required parameter `User` missing when calling createUsersWithListInput." } - $LocalVarBodyParameter = $User | ConvertTo-Json -Depth 100 + $LocalVarBodyParameter = ,$User | ConvertTo-Json -Depth 100 $LocalVarResult = Invoke-PSApiClient -Method 'POST' ` -Uri $LocalVarUri `