From 3316f17ed5b12ac6a0b96af636f2d85431e3a179 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 31 Mar 2020 19:10:27 +0800 Subject: [PATCH] [PS][PowerShell] fix passthru, use switch instead of bool (#5768) * fix passthru, use switch * remove line --- .../configuration.mustache | 20 +++++++++++++------ .../src/PSPetstore/Client/PSConfiguration.ps1 | 20 +++++++++++++------ .../src/PSPetstore/PSPetstore.psd1 | 2 +- .../tests/Petstore.Tests.ps1 | 7 +++++++ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache index b6d023d29eb1..ad5cb6335acf 100644 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache @@ -89,6 +89,9 @@ Skip certificate verification .PARAMETER DefaultHeaders Default HTTP headers to be included in the HTTP request +.PARAMETER PassThru +Return an object of the Configuration + .OUTPUTS System.Collections.Hashtable @@ -108,10 +111,9 @@ function Set-{{{apiNamePrefix}}}Configuration { [string]$Cookie, [AllowEmptyString()] [string]$AccessToken, - [switch]$PassThru, - [bool]$SkipCertificateCheck, + [switch]$SkipCertificateCheck, [hashtable]$DefaultHeaders, - [switch]$Force + [switch]$PassThru ) Process { @@ -144,13 +146,19 @@ function Set-{{{apiNamePrefix}}}Configuration { $Script:Configuration['AccessToken'] = $AccessToken } - If ($SkipCertificateCheck) { - $Script:Configuration['SkipCertificateCheck'] = $SkipCertificateCheck - } + If ($SkipCertificateCheck.IsPresent) { + $Script:Configuration['SkipCertificateCheck'] = $true + } else { + $Script:Configuration['SkipCertificateCheck'] = $false + } If ($DefaultHeaders) { $Script:Configuration['DefaultHeaders'] = $DefaultHeaders } + + If ($PassThru.IsPresent) { + $Script:Configuration + } } } diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1 index a2c42d6cd9ef..61fa67486abc 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1 @@ -95,6 +95,9 @@ Skip certificate verification .PARAMETER DefaultHeaders Default HTTP headers to be included in the HTTP request +.PARAMETER PassThru +Return an object of the Configuration + .OUTPUTS System.Collections.Hashtable @@ -114,10 +117,9 @@ function Set-PSConfiguration { [string]$Cookie, [AllowEmptyString()] [string]$AccessToken, - [switch]$PassThru, - [bool]$SkipCertificateCheck, + [switch]$SkipCertificateCheck, [hashtable]$DefaultHeaders, - [switch]$Force + [switch]$PassThru ) Process { @@ -150,13 +152,19 @@ function Set-PSConfiguration { $Script:Configuration['AccessToken'] = $AccessToken } - If ($SkipCertificateCheck) { - $Script:Configuration['SkipCertificateCheck'] = $SkipCertificateCheck - } + If ($SkipCertificateCheck.IsPresent) { + $Script:Configuration['SkipCertificateCheck'] = $true + } else { + $Script:Configuration['SkipCertificateCheck'] = $false + } If ($DefaultHeaders) { $Script:Configuration['DefaultHeaders'] = $DefaultHeaders } + + If ($PassThru.IsPresent) { + $Script:Configuration + } } } diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1 index 581a5d04501c..04e12c68792b 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1 @@ -3,7 +3,7 @@ # # Generated by: OpenAPI Generator Team # -# Generated on: 3/30/20 +# Generated on: 3/31/20 # @{ diff --git a/samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1 b/samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1 index 9edcf67e9d94..c2f8f170c907 100644 --- a/samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1 +++ b/samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1 @@ -94,5 +94,12 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' { $Configuration["DefaultHeaders"]["TestKey"] | Should Be "TestValue" } + + It "Configuration tests" { + $Conf = Get-PSConfiguration + $Conf["SkipCertificateCheck"] | Should Be $false + $Conf = Set-PSConfiguration -PassThru -SkipCertificateCheck + $Conf["SkipCertificateCheck"] | Should Be $true + } } }