Skip to content

Commit 66deff6

Browse files
wing328michaelpro1
authored andcommitted
various enhancement to ps exp generator (OpenAPITools#5875)
1 parent 4977fd1 commit 66deff6

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function Set-{{{apiNamePrefix}}}Configuration {
121121
If ($BaseUrl) {
122122
# validate URL
123123
$URL = $BaseUrl -as [System.URI]
124-
if (!($URL.AbsoluteURI -ne $null -and $URL.Scheme -match '[http|https]')) {
124+
if (!($null -ne $URL.AbsoluteURI -and $URL.Scheme -match '[http|https]')) {
125125
throw "Invalid URL '$($BaseUrl)' cannot be used in the base URL."
126126
}
127127

@@ -349,15 +349,15 @@ function Get-{{apiNamePrefix}}UrlFromHostSetting {
349349
$Hosts = Get-{{apiNamePrefix}}HostSetting
350350

351351
# check array index out of bound
352-
if ($Index -lt 0 -or $Index -gt $Hosts.Length) {
352+
if ($Index -lt 0 -or $Index -ge $Hosts.Length) {
353353
throw "Invalid index $index when selecting the host. Must be less than $($Hosts.Length)"
354354
}
355355

356-
$Host = $Hosts[$Index];
357-
$Url = $Host["Url"];
356+
$MyHost = $Hosts[$Index];
357+
$Url = $MyHost["Url"];
358358

359359
# go through variable and assign a value
360-
foreach ($h in $Host["Variables"].GetEnumerator()) {
360+
foreach ($h in $MyHost["Variables"].GetEnumerator()) {
361361
if ($Variables.containsKey($h.Name)) { # check to see if it's in the variables provided by the user
362362
if ($h.Value["EnumValues"] -Contains $Variables[$h.Name]) {
363363
$Url = $Url.replace("{$($h.Name)}", $Variables[$h.Name])

samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function Set-PSConfiguration {
127127
If ($BaseUrl) {
128128
# validate URL
129129
$URL = $BaseUrl -as [System.URI]
130-
if (!($URL.AbsoluteURI -ne $null -and $URL.Scheme -match '[http|https]')) {
130+
if (!($null -ne $URL.AbsoluteURI -and $URL.Scheme -match '[http|https]')) {
131131
throw "Invalid URL '$($BaseUrl)' cannot be used in the base URL."
132132
}
133133

@@ -365,15 +365,15 @@ function Get-PSUrlFromHostSetting {
365365
$Hosts = Get-PSHostSetting
366366

367367
# check array index out of bound
368-
if ($Index -lt 0 -or $Index -gt $Hosts.Length) {
368+
if ($Index -lt 0 -or $Index -ge $Hosts.Length) {
369369
throw "Invalid index $index when selecting the host. Must be less than $($Hosts.Length)"
370370
}
371371

372-
$Host = $Hosts[$Index];
373-
$Url = $Host["Url"];
372+
$MyHost = $Hosts[$Index];
373+
$Url = $MyHost["Url"];
374374

375375
# go through variable and assign a value
376-
foreach ($h in $Host["Variables"].GetEnumerator()) {
376+
foreach ($h in $MyHost["Variables"].GetEnumerator()) {
377377
if ($Variables.containsKey($h.Name)) { # check to see if it's in the variables provided by the user
378378
if ($h.Value["EnumValues"] -Contains $Variables[$h.Name]) {
379379
$Url = $Url.replace("{$($h.Name)}", $Variables[$h.Name])

samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
133133
Get-PSUrlFromHostSetting -Index 0 | Should Be "http://petstore.swagger.io:80/v2"
134134
Get-PSUrlFromHostSetting -Index 0 -Variables @{ "port" = "8080" } | Should Be "http://petstore.swagger.io:8080/v2"
135135
#Get-PSUrlFromHostSetting -Index 2 | Should -Throw -ExceptionType ([RuntimeException])
136-
#Get-PSUrlFromHostSetting -Index 2 | Should -Throw # "Invalid index 2 when selecting the host. Must be less than 2"
137-
#Get-PSUrlFromHostSetting -Index 0 -Variables @{ "port" = "1234" } | Should Throw "The variable 'port' in the host URL has invalid value 1234. Must be 80,8080"
136+
#Get-PSUrlFromHostSetting -Index 2 -ErrorAction Stop | Should -Throw "RuntimeException: Invalid index 2 when selecting the host. Must be less than 2"
137+
#Get-PSUrlFromHostSetting -Index 0 -Variables @{ "port" = "1234" } -ErrorAction Stop | Should -Throw "RuntimeException: The variable 'port' in the host URL has invalid value 1234. Must be 80,8080"
138138

139139
}
140140

0 commit comments

Comments
 (0)