forked from loafle/openapi-generator-original
rename hostsetting, validate base url (#5821)
This commit is contained in:
parent
242c2e8544
commit
42e87c8f33
@ -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
|
||||
}
|
||||
|
||||
@ -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}}
|
||||
@{
|
||||
@ -330,7 +336,7 @@ Get the URL from the host settings.
|
||||
|
||||
String
|
||||
#>
|
||||
function Get-{{apiNamePrefix}}UrlFromHostSettings {
|
||||
function Get-{{apiNamePrefix}}UrlFromHostSetting {
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
@ -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";
|
||||
@ -346,7 +352,7 @@ Get the URL from the host settings.
|
||||
|
||||
String
|
||||
#>
|
||||
function Get-PSUrlFromHostSettings {
|
||||
function Get-PSUrlFromHostSetting {
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
@ -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) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
#
|
||||
# Generated by: OpenAPI Generator Team
|
||||
#
|
||||
# Generated on: 4/3/20
|
||||
# Generated on: 4/4/20
|
||||
#
|
||||
|
||||
@{
|
||||
@ -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 = @()
|
||||
|
@ -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"
|
||||
@ -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"
|
||||
|
||||
}
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user