Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
rename hostsetting, validate base url
  • Loading branch information
wing328 committed Apr 4, 2020
commit d61e74dda3a69c797076038337ee7fb97ed7fa59
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ function Set-{{{apiNamePrefix}}}Configuration {
Process {

If ($BaseUrl) {
# validate URL
$URL = $BaseUrl -as [System.URI]
if (!($URL.AbsoluteURI -ne $null -and $URL.Scheme -match '[http|https]')) {
throw "Invalid URL '$($BaseUrl)' cannot be used in the base URL."
}

$Script:Configuration["BaseUrl"] = $BaseUrl
}

Expand Down Expand Up @@ -278,7 +284,7 @@ Get the host setting in the form of array of hashtables.

System.Collections.Hashtable[]
#>
function Get-{{apiNamePrefix}}HostSettings {
function Get-{{apiNamePrefix}}HostSetting {
return @(
{{#servers}}
@{
Expand Down Expand Up @@ -330,7 +336,7 @@ Get the URL from the host settings.

String
#>
function Get-{{apiNamePrefix}}UrlFromHostSettings {
function Get-{{apiNamePrefix}}UrlFromHostSetting {

[CmdletBinding()]
Param(
Expand All @@ -340,7 +346,7 @@ function Get-{{apiNamePrefix}}UrlFromHostSettings {
)

Process {
$Hosts = Get-{{apiNamePrefix}}HostSettings
$Hosts = Get-{{apiNamePrefix}}HostSetting

# check array index out of bound
if ($Index -lt 0 -or $Index -gt $Hosts.Length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ function Set-PSConfiguration {
Process {

If ($BaseUrl) {
# validate URL
$URL = $BaseUrl -as [System.URI]
if (!($URL.AbsoluteURI -ne $null -and $URL.Scheme -match '[http|https]')) {
throw "Invalid URL '$($BaseUrl)' cannot be used in the base URL."
}

$Script:Configuration["BaseUrl"] = $BaseUrl
}

Expand Down Expand Up @@ -284,7 +290,7 @@ Get the host setting in the form of array of hashtables.

System.Collections.Hashtable[]
#>
function Get-PSHostSettings {
function Get-PSHostSetting {
return @(
@{
"Url" = "http://{server}.swagger.io:{port}/v2";
Expand Down Expand Up @@ -346,7 +352,7 @@ Get the URL from the host settings.

String
#>
function Get-PSUrlFromHostSettings {
function Get-PSUrlFromHostSetting {

[CmdletBinding()]
Param(
Expand All @@ -356,7 +362,7 @@ function Get-PSUrlFromHostSettings {
)

Process {
$Hosts = Get-PSHostSettings
$Hosts = Get-PSHostSetting

# check array index out of bound
if ($Index -lt 0 -or $Index -gt $Hosts.Length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: OpenAPI Generator Team
#
# Generated on: 4/3/20
# Generated on: 4/4/20
#

@{
Expand Down Expand Up @@ -81,8 +81,8 @@ FunctionsToExport = 'Add-PSPet', 'Remove-Pet', 'Find-PSPetsByStatus', 'Find-PSPe
'Initialize-PSPet', 'Initialize-PSTag', 'Initialize-PSUser',
'Get-PSConfiguration', 'Set-PSConfiguration',
'Set-PSConfigurationApiKey', 'Set-PSConfigurationApiKeyPrefix',
'Set-PSConfigurationDefaultHeader', 'Get-PSHostSettings',
'Get-PSUrlFromHostSettings'
'Set-PSConfigurationDefaultHeader', 'Get-PSHostSetting',
'Get-PSUrlFromHostSetting'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
}

Context 'Configuration' {
It 'Get-PSHostSettings tests' {
It 'Get-PSHostSetting tests' {

$HS = Get-PSHostSettings
$HS = Get-PSHostSetting

$HS[0]["Url"] | Should Be "http://{server}.swagger.io:{port}/v2"
$HS[0]["Description"] | Should Be "petstore server"
Expand All @@ -129,12 +129,12 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {

}

It "Get-PSUrlFromHostSettings tests" {
Get-PSUrlFromHostSettings -Index 0 | Should Be "http://petstore.swagger.io:80/v2"
Get-PSUrlFromHostSettings -Index 0 -Variables @{ "port" = "8080" } | Should Be "http://petstore.swagger.io:8080/v2"
#Get-PSUrlFromHostSettings -Index 2 | Should -Throw -ExceptionType ([RuntimeException])
#Get-PSUrlFromHostSettings -Index 2 | Should -Throw # "Invalid index 2 when selecting the host. Must be less than 2"
#Get-PSUrlFromHostSettings -Index 0 -Variables @{ "port" = "1234" } | Should Throw "The variable 'port' in the host URL has invalid value 1234. Must be 80,8080"
It "Get-PSUrlFromHostSetting 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"

}

Expand All @@ -153,6 +153,12 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
$Conf["SkipCertificateCheck"] | Should Be $false
$Conf = Set-PSConfiguration -PassThru -SkipCertificateCheck
$Conf["SkipCertificateCheck"] | Should Be $true
$Conf = Set-PSConfiguration -PassThru # reset SkipCertificateCheck
}

It "Base URL tests" {
$Conf = Set-PSConfiguration -BaseURL "http://localhost"
$Conf = Set-PSConfiguration -BaseURL "https://localhost:8080/api"
}
}
}