From c5d6220937aa66ba1ff7207faad70e0afcc9af60 Mon Sep 17 00:00:00 2001 From: condorcorde Date: Thu, 1 Feb 2024 20:43:50 +0100 Subject: [PATCH] Changes after build --- .../src/PSOpenAPITools/Private/ApiClient.ps1 | 26 ++++++++++++------- .../src/PSPetstore/Private/PSApiClient.ps1 | 26 ++++++++++++------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/samples/client/echo_api/powershell/src/PSOpenAPITools/Private/ApiClient.ps1 b/samples/client/echo_api/powershell/src/PSOpenAPITools/Private/ApiClient.ps1 index 832786cdae77..62dd76dbda6c 100644 --- a/samples/client/echo_api/powershell/src/PSOpenAPITools/Private/ApiClient.ps1 +++ b/samples/client/echo_api/powershell/src/PSOpenAPITools/Private/ApiClient.ps1 @@ -58,7 +58,7 @@ function Invoke-ApiClient { } # accept, content-type headers - $Accept = SelectHeaders -Headers $Accepts + $Accept = SelectHeaders -Headers $Accepts -Multiple if ($Accept) { $HeaderParameters['Accept'] = $Accept } @@ -182,24 +182,30 @@ function Invoke-ApiClient { } } -# Select JSON MIME if present, otherwise choose the first one if available +# Select multiple types for Accept header +# Select JSON MIME if present, otherwise choose the first one if available for Content-Type header function SelectHeaders { Param( [Parameter(Mandatory)] [AllowEmptyCollection()] - [String[]]$Headers + [String[]]$Headers, + [Parameter(Mandatory=$false)] + [switch]$Multiple ) - foreach ($Header in $Headers) { - if (IsJsonMIME -MIME $Header) { - return $Header - } - } - if (!($Headers) -or $Headers.Count -eq 0) { return $null + } + + if ($Multiple) { + return [string]::Join(', ', $Headers) # join multiple types if they are provided } else { - return $Headers[0] # return the first one + foreach ($Header in $Headers) { + if (IsJsonMIME -MIME $Header) { + return $Header # return the first type matching a JSON MIME + } + } + return $Headers[0] # else return the first one } } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 index 048cb4138a3b..7f6c5482fe53 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 @@ -57,7 +57,7 @@ function Invoke-PSApiClient { } # accept, content-type headers - $Accept = SelectHeaders -Headers $Accepts + $Accept = SelectHeaders -Headers $Accepts -Multiple if ($Accept) { $HeaderParameters['Accept'] = $Accept } @@ -198,24 +198,30 @@ function Invoke-PSApiClient { } } -# Select JSON MIME if present, otherwise choose the first one if available +# Select multiple types for Accept header +# Select JSON MIME if present, otherwise choose the first one if available for Content-Type header function SelectHeaders { Param( [Parameter(Mandatory)] [AllowEmptyCollection()] - [String[]]$Headers + [String[]]$Headers, + [Parameter(Mandatory=$false)] + [switch]$Multiple ) - foreach ($Header in $Headers) { - if (IsJsonMIME -MIME $Header) { - return $Header - } - } - if (!($Headers) -or $Headers.Count -eq 0) { return $null + } + + if ($Multiple) { + return [string]::Join(', ', $Headers) # join multiple types if they are provided } else { - return $Headers[0] # return the first one + foreach ($Header in $Headers) { + if (IsJsonMIME -MIME $Header) { + return $Header # return the first type matching a JSON MIME + } + } + return $Headers[0] # else return the first one } }