Skip to content

Commit

Permalink
various enhancement to ps exp generator (#5875)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Apr 9, 2020
1 parent 7342077 commit 46f3b4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function Set-{{{apiNamePrefix}}}Configuration {
If ($BaseUrl) {
# validate URL
$URL = $BaseUrl -as [System.URI]
if (!($URL.AbsoluteURI -ne $null -and $URL.Scheme -match '[http|https]')) {
if (!($null -ne $URL.AbsoluteURI -and $URL.Scheme -match '[http|https]')) {
throw "Invalid URL '$($BaseUrl)' cannot be used in the base URL."
}

Expand Down Expand Up @@ -349,15 +349,15 @@ function Get-{{apiNamePrefix}}UrlFromHostSetting {
$Hosts = Get-{{apiNamePrefix}}HostSetting

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

$Host = $Hosts[$Index];
$Url = $Host["Url"];
$MyHost = $Hosts[$Index];
$Url = $MyHost["Url"];

# go through variable and assign a value
foreach ($h in $Host["Variables"].GetEnumerator()) {
foreach ($h in $MyHost["Variables"].GetEnumerator()) {
if ($Variables.containsKey($h.Name)) { # check to see if it's in the variables provided by the user
if ($h.Value["EnumValues"] -Contains $Variables[$h.Name]) {
$Url = $Url.replace("{$($h.Name)}", $Variables[$h.Name])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function Set-PSConfiguration {
If ($BaseUrl) {
# validate URL
$URL = $BaseUrl -as [System.URI]
if (!($URL.AbsoluteURI -ne $null -and $URL.Scheme -match '[http|https]')) {
if (!($null -ne $URL.AbsoluteURI -and $URL.Scheme -match '[http|https]')) {
throw "Invalid URL '$($BaseUrl)' cannot be used in the base URL."
}

Expand Down Expand Up @@ -365,15 +365,15 @@ function Get-PSUrlFromHostSetting {
$Hosts = Get-PSHostSetting

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

$Host = $Hosts[$Index];
$Url = $Host["Url"];
$MyHost = $Hosts[$Index];
$Url = $MyHost["Url"];

# go through variable and assign a value
foreach ($h in $Host["Variables"].GetEnumerator()) {
foreach ($h in $MyHost["Variables"].GetEnumerator()) {
if ($Variables.containsKey($h.Name)) { # check to see if it's in the variables provided by the user
if ($h.Value["EnumValues"] -Contains $Variables[$h.Name]) {
$Url = $Url.replace("{$($h.Name)}", $Variables[$h.Name])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
Get-PSUrlFromHostSetting -Index 0 | Should Be "http://petstore.swagger.io:80/v2"
Get-PSUrlFromHostSetting -Index 0 -Variables @{ "port" = "8080" } | Should Be "http://petstore.swagger.io:8080/v2"
#Get-PSUrlFromHostSetting -Index 2 | Should -Throw -ExceptionType ([RuntimeException])
#Get-PSUrlFromHostSetting -Index 2 | Should -Throw # "Invalid index 2 when selecting the host. Must be less than 2"
#Get-PSUrlFromHostSetting -Index 0 -Variables @{ "port" = "1234" } | Should Throw "The variable 'port' in the host URL has invalid value 1234. Must be 80,8080"
#Get-PSUrlFromHostSetting -Index 2 -ErrorAction Stop | Should -Throw "RuntimeException: Invalid index 2 when selecting the host. Must be less than 2"
#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"

}

Expand Down

0 comments on commit 46f3b4a

Please sign in to comment.