From 9f2bd313ffdf9b177307979524925912cfcfea7c Mon Sep 17 00:00:00 2001 From: Syd Besco <48411111+syd-besco@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:57:21 +0200 Subject: [PATCH] [POWERSHELL] fix: keep array context when converting to json (#19535) --- .../src/main/resources/powershell/api.mustache | 2 +- .../petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell/api.mustache b/modules/openapi-generator/src/main/resources/powershell/api.mustache index 78444914f3d..9247b5df306 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api.mustache @@ -188,7 +188,7 @@ function {{{vendorExtensions.x-powershell-method-name}}} { {{/isNullable}} {{/required}} {{#isArray}} - $LocalVarBodyParameter = ,${{{paramName}}} | ConvertTo-Json -Depth 100 + $LocalVarBodyParameter = ConvertTo-Json @(${{{paramName}}}) -Depth 100 {{/isArray}} {{^isArray}} $LocalVarBodyParameter = ${{{paramName}}} | ConvertTo-Json -Depth 100 diff --git a/samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 index d1a485d31e2..b126ec0e110 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 = ConvertTo-Json @($User) -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 = ConvertTo-Json @($User) -Depth 100 $LocalVarResult = Invoke-PSApiClient -Method 'POST' ` -Uri $LocalVarUri `