From 4de97a47e3be8d0c3846ba83b780bc3660dbd218 Mon Sep 17 00:00:00 2001 From: Vikrant Balyan Date: Mon, 23 Mar 2020 22:34:09 +0530 Subject: [PATCH] Adds configuration option to skip certificate check. Fixes a typo. Fixes an issue which was restricting from cookie to get consumed (#5657) --- .../api_client.mustache | 23 +++++++++++++++---- .../configuration.mustache | 9 ++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/api_client.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/api_client.mustache index 51029124d7c..e7824549e0c 100644 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/powershell-experimental/api_client.mustache @@ -34,14 +34,17 @@ function Invoke-{{{apiNamePrefix}}}ApiClient { $Configuration = Get-{{{apiNamePrefix}}}Configuration $RequestUri = $Configuration["BaseUrl"] + $Uri + $SkipCertificateCheck = $Configuration["SkipCertificateCheck"] # cookie parameters - foreach ($Parameter in $CookieParameters) { - if ($CookieParameters[$Parameter]) { - $HeaderParameters["Cookie"] = $CookieParameters[$Parameter] + foreach ($Parameter in $CookieParameters.GetEnumerator()) { + if ($Parameter.Name -eq "cookieAuth") { + $HeaderParameters["Cookie"] = $Parameter.Value + } else { + $HeaderParameters[$Parameter.Name] = $Parameter.Value } } - if ($CookieParametters -and $CookieParameters.Count -gt 1) { + if ($CookieParameters -and $CookieParameters.Count -gt 1) { Write-Warning "Multipe cookie parameters found. Curently only the first one is supported/used" } @@ -80,11 +83,21 @@ function Invoke-{{{apiNamePrefix}}}ApiClient { $RequestBody = $Body } - $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` + if ($SkipCertificateCheck -eq $true) { + $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` + -Method $Method ` + -Headers $HeaderParameters ` + -Body $RequestBody ` + -ErrorAction Stop ` + -SkipCertificateCheck + + } else { + $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` -Method $Method ` -Headers $HeaderParameters ` -Body $RequestBody ` -ErrorAction Stop + } return @{ Response = DeserializeResponse -Response $Response -ReturnType $ReturnType 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 6d04b766bb1..029bdcb549b 100644 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache @@ -28,6 +28,10 @@ function Get-{{apiNamePrefix}}Configuration { $Configuration["ApiKeyPrefix"] = @{} } + if (!$Configuration.containsKey("SkipCertificateCheck")) { + $Configuration["SkipCertificateCheck"] = $false + } + Return $Configuration } @@ -48,6 +52,7 @@ function Set-{{{apiNamePrefix}}}Configuration { [AllowEmptyString()] [string]$AccessToken, [switch]$PassThru, + [bool]$SkipCertificateCheck, [switch]$Force ) @@ -80,6 +85,10 @@ function Set-{{{apiNamePrefix}}}Configuration { If ($AccessToken) { $Script:Configuration['AccessToken'] = $AccessToken } + + If ($SkipCertificateCheck) { + $Script:Configuration['SkipCertificateCheck'] = $SkipCertificateCheck + } } }