From c244c230531d97ee1fadeabf37ac5ce56c532bb5 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 21 Nov 2021 23:03:25 +0800 Subject: [PATCH] better null comparison (#10915) --- .../src/main/resources/powershell/api_client.mustache | 6 +++--- .../src/main/resources/powershell/appveyor.mustache | 2 +- .../src/main/resources/powershell/configuration.mustache | 2 +- .../src/main/resources/powershell/model_simple.mustache | 2 +- samples/client/petstore/powershell/appveyor.yml | 2 +- .../powershell/src/PSPetstore/Client/PSConfiguration.ps1 | 2 +- .../client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 | 4 ++-- .../powershell/src/PSPetstore/Private/PSApiClient.ps1 | 6 +++--- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell/api_client.mustache b/modules/openapi-generator/src/main/resources/powershell/api_client.mustache index 2435b7b0ced..f7769247fc4 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api_client.mustache @@ -144,7 +144,7 @@ function Invoke-{{{apiNamePrefix}}}ApiClient { {{/hasHttpSignatureMethods}} if ($SkipCertificateCheck -eq $true) { - if ($Configuration["Proxy"] -eq $null) { + if ($null -eq $Configuration["Proxy"]) { # skip certification check, no proxy $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` -Method $Method ` @@ -166,7 +166,7 @@ function Invoke-{{{apiNamePrefix}}}ApiClient { -ProxyUseDefaultCredentials } } else { - if ($Configuration["Proxy"] -eq $null) { + if ($null -eq $Configuration["Proxy"]) { # perform certification check, no proxy $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` -Method $Method ` @@ -241,7 +241,7 @@ function DeserializeResponse { [string[]]$ContentTypes ) - If ($ContentTypes -eq $null) { + If ($null -eq $ContentTypes) { $ContentTypes = [string[]]@() } diff --git a/modules/openapi-generator/src/main/resources/powershell/appveyor.mustache b/modules/openapi-generator/src/main/resources/powershell/appveyor.mustache index d1047879e53..1127a6fc20c 100644 --- a/modules/openapi-generator/src/main/resources/powershell/appveyor.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/appveyor.mustache @@ -20,7 +20,7 @@ test_script: } deploy_script: - pwsh: | - if ($env:APPVEYOR_REPO_TAG -eq $true -and $env:NuGetApiKey -ne $null) { + if ($env:APPVEYOR_REPO_TAG -eq $true -and $null -ne $env:NuGetApiKey) { .\Build.ps1 try { Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\src\{{{packageName}}}\ -Confirm:$False -Verbose diff --git a/modules/openapi-generator/src/main/resources/powershell/configuration.mustache b/modules/openapi-generator/src/main/resources/powershell/configuration.mustache index 21762dbf5c4..0e674f1f560 100644 --- a/modules/openapi-generator/src/main/resources/powershell/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/configuration.mustache @@ -172,7 +172,7 @@ function Set-{{{apiNamePrefix}}}Configuration { $Script:Configuration['DefaultHeaders'] = $DefaultHeaders } - If ($Proxy -ne $null) { + If ($null -ne $Proxy) { If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") { throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque." } diff --git a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache index 94f92c3dd03..f7954411df8 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache @@ -73,7 +73,7 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} { {{#vars}} {{^isNullable}} {{#required}} - if (${{{name}}} -eq $null) { + if ($null -eq ${{{name}}}) { throw "invalid value for '{{{name}}}', '{{{name}}}' cannot be null." } diff --git a/samples/client/petstore/powershell/appveyor.yml b/samples/client/petstore/powershell/appveyor.yml index b6967a7c7b6..86b98d394b5 100644 --- a/samples/client/petstore/powershell/appveyor.yml +++ b/samples/client/petstore/powershell/appveyor.yml @@ -26,7 +26,7 @@ test_script: } deploy_script: - pwsh: | - if ($env:APPVEYOR_REPO_TAG -eq $true -and $env:NuGetApiKey -ne $null) { + if ($env:APPVEYOR_REPO_TAG -eq $true -and $null -ne $env:NuGetApiKey) { .\Build.ps1 try { Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\src\PSPetstore\ -Confirm:$False -Verbose diff --git a/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 index 67e42865831..d24a405660d 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 @@ -178,7 +178,7 @@ function Set-PSConfiguration { $Script:Configuration['DefaultHeaders'] = $DefaultHeaders } - If ($Proxy -ne $null) { + If ($null -ne $Proxy) { If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") { throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque." } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 index eebc0a22260..5207e6986f6 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 @@ -59,11 +59,11 @@ function Initialize-PSPet { 'Creating PSCustomObject: PSPetstore => PSPet' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug - if ($Name -eq $null) { + if ($null -eq $Name) { throw "invalid value for 'Name', 'Name' cannot be null." } - if ($PhotoUrls -eq $null) { + if ($null -eq $PhotoUrls) { throw "invalid value for 'PhotoUrls', 'PhotoUrls' cannot be null." } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 index 11745f18614..be338cd33eb 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 @@ -131,7 +131,7 @@ function Invoke-PSApiClient { } if ($SkipCertificateCheck -eq $true) { - if ($Configuration["Proxy"] -eq $null) { + if ($null -eq $Configuration["Proxy"]) { # skip certification check, no proxy $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` -Method $Method ` @@ -153,7 +153,7 @@ function Invoke-PSApiClient { -ProxyUseDefaultCredentials } } else { - if ($Configuration["Proxy"] -eq $null) { + if ($null -eq $Configuration["Proxy"]) { # perform certification check, no proxy $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` -Method $Method ` @@ -228,7 +228,7 @@ function DeserializeResponse { [string[]]$ContentTypes ) - If ($ContentTypes -eq $null) { + If ($null -eq $ContentTypes) { $ContentTypes = [string[]]@() }