From 45e4fa1633ea06b8e94e6c44b7bc2516aa56b94f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 16 Sep 2025 15:24:22 +0800 Subject: [PATCH] Add workflow for PowerShell clients (#21979) * add workflow for powershell client * update * fix container * import, test * combine * use localhost * update tests * remove powershell tests from appveyor.yml --- .github/workflows/samples-powershell.yaml | 40 +++++++++++++++++++ appveyor.yml | 6 --- ...odels-for-testing-with-http-signature.yaml | 2 + .../powershell/.openapi-generator-ignore | 3 ++ samples/client/petstore/powershell/README.md | 2 +- .../powershell/docs/PSAnotherFakeApi.md | 2 +- .../petstore/powershell/docs/PSDefaultApi.md | 2 +- .../petstore/powershell/docs/PSFakeApi.md | 2 +- .../docs/PSFakeClassnameTags123Api.md | 2 +- .../petstore/powershell/docs/PSPetApi.md | 2 +- .../petstore/powershell/docs/PSStoreApi.md | 2 +- .../petstore/powershell/docs/PSUserApi.md | 2 +- .../src/PSPetstore/Client/PSConfiguration.ps1 | 6 ++- .../powershell/tests/Petstore.Tests.ps1 | 14 +++---- 14 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/samples-powershell.yaml diff --git a/.github/workflows/samples-powershell.yaml b/.github/workflows/samples-powershell.yaml new file mode 100644 index 00000000000..208cf69332f --- /dev/null +++ b/.github/workflows/samples-powershell.yaml @@ -0,0 +1,40 @@ +name: Samples PowerShell + +on: + push: + paths: + - samples/client/petstore/powershell/** + pull_request: + paths: + - samples/client/petstore/powershell/** +jobs: + build: + runs-on: ubuntu-latest + name: Test Powershell Clients + strategy: + matrix: + sample: + - samples/client/petstore/powershell/ + services: + petstore-api: + image: swaggerapi/petstore + ports: + - 80:8080 + env: + SWAGGER_HOST: http://petstore.swagger.io + SWAGGER_BASE_PATH: /v2 + steps: + - uses: actions/checkout@v5 + - name: Build the client + working-directory: ${{ matrix.sample }} + shell: pwsh + run: | + ./Build.ps1 + - name: Test + working-directory: ${{ matrix.sample }} + shell: pwsh + run: | + Import-Module -Name './src/PSPetstore' + Invoke-Pester -PassThru + + diff --git a/appveyor.yml b/appveyor.yml index 3c6471ae7a7..08ee15a8040 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,6 @@ install: - cmd: docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore - ps: Start-Sleep -s 120 - ps: $PSVersionTable.PSVersion - - ps: Install-Module -Name Pester -Force -Scope CurrentUser -SkipPublisherCheck build_script: - dotnet --info # build C# aspnetcore 5.0 server @@ -108,11 +107,6 @@ test_script: # - .\bin\windows\run-all-petstore.cmd # generate all petstore clients (openapi3) # - .\bin\openapi3\windows\run-all-petstore.cmd - - # test ps petstore - - ps: | - cd samples\client\petstore\powershell\ - .\CIRunTest.ps1 cache: - C:\maven\ - C:\gradle\ diff --git a/modules/openapi-generator/src/test/resources/3_0/powershell/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/powershell/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 4fb684961ea..52ec6279e0c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/powershell/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/powershell/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -31,6 +31,7 @@ paths: $ref: '#/components/schemas/Foo' /pet: servers: + - url: 'http://localhost/v2' - url: 'http://petstore.swagger.io/v2' - url: 'http://path-server-test.petstore.local/v2' post: @@ -1170,6 +1171,7 @@ paths: schema: $ref: '#/components/schemas/ArrayOfEnums' servers: + - url: 'http://localhost/v2' - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server variables: diff --git a/samples/client/petstore/powershell/.openapi-generator-ignore b/samples/client/petstore/powershell/.openapi-generator-ignore index 7484ee590a3..c5b04829c20 100644 --- a/samples/client/petstore/powershell/.openapi-generator-ignore +++ b/samples/client/petstore/powershell/.openapi-generator-ignore @@ -21,3 +21,6 @@ #docs/*.md # Then explicitly reverse the ignore rule for a single file: #!docs/README.md +# +# +# diff --git a/samples/client/petstore/powershell/README.md b/samples/client/petstore/powershell/README.md index 66eb863c9d0..5aa81e0cea3 100644 --- a/samples/client/petstore/powershell/README.md +++ b/samples/client/petstore/powershell/README.md @@ -52,7 +52,7 @@ For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debug ## Documentation for API Endpoints -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSAnotherFakeApi.md b/samples/client/petstore/powershell/docs/PSAnotherFakeApi.md index 7f10645464f..c4b85e51217 100644 --- a/samples/client/petstore/powershell/docs/PSAnotherFakeApi.md +++ b/samples/client/petstore/powershell/docs/PSAnotherFakeApi.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSAnotherFakeApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSDefaultApi.md b/samples/client/petstore/powershell/docs/PSDefaultApi.md index a75b9c9b0c1..af1bad168cc 100644 --- a/samples/client/petstore/powershell/docs/PSDefaultApi.md +++ b/samples/client/petstore/powershell/docs/PSDefaultApi.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSDefaultApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSFakeApi.md b/samples/client/petstore/powershell/docs/PSFakeApi.md index 2fbbcd7e743..6aa3b3a3532 100644 --- a/samples/client/petstore/powershell/docs/PSFakeApi.md +++ b/samples/client/petstore/powershell/docs/PSFakeApi.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSFakeApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSFakeClassnameTags123Api.md b/samples/client/petstore/powershell/docs/PSFakeClassnameTags123Api.md index 02bfd8628a2..6583d204fad 100644 --- a/samples/client/petstore/powershell/docs/PSFakeClassnameTags123Api.md +++ b/samples/client/petstore/powershell/docs/PSFakeClassnameTags123Api.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSFakeClassnameTags123Api -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSPetApi.md b/samples/client/petstore/powershell/docs/PSPetApi.md index 48d7f783ce4..829166f7565 100644 --- a/samples/client/petstore/powershell/docs/PSPetApi.md +++ b/samples/client/petstore/powershell/docs/PSPetApi.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSPetApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSStoreApi.md b/samples/client/petstore/powershell/docs/PSStoreApi.md index 2ff14209a04..24eaa6a083d 100644 --- a/samples/client/petstore/powershell/docs/PSStoreApi.md +++ b/samples/client/petstore/powershell/docs/PSStoreApi.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSStoreApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/docs/PSUserApi.md b/samples/client/petstore/powershell/docs/PSUserApi.md index d1f99ed9d40..1e8a3a54154 100644 --- a/samples/client/petstore/powershell/docs/PSUserApi.md +++ b/samples/client/petstore/powershell/docs/PSUserApi.md @@ -1,6 +1,6 @@ # PSPetstore.PSPetstore\Api.PSUserApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *http://localhost/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 index 043b2f9e846..43daeb442c5 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 @@ -23,7 +23,7 @@ function Get-PSConfiguration { $Configuration = $Script:Configuration if ([string]::IsNullOrEmpty($Configuration["BaseUrl"])) { - $Configuration["BaseUrl"] = "http://petstore.swagger.io:80/v2"; + $Configuration["BaseUrl"] = "http://localhost/v2"; } if (!$Configuration.containsKey("Username")) { @@ -311,6 +311,10 @@ System.Collections.Hashtable[] #> function Get-PSHostSetting { return ,@( + @{ + "Url" = "http://localhost/v2"; + "Description" = "No description provided"; + }, @{ "Url" = "http://{server}.swagger.io:{port}/v2"; "Description" = "petstore server"; diff --git a/samples/client/petstore/powershell/tests/Petstore.Tests.ps1 b/samples/client/petstore/powershell/tests/Petstore.Tests.ps1 index 6e64665dd65..6a1c2433656 100644 --- a/samples/client/petstore/powershell/tests/Petstore.Tests.ps1 +++ b/samples/client/petstore/powershell/tests/Petstore.Tests.ps1 @@ -140,19 +140,19 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' { $HS = Get-PSHostSetting - $HS[0]["Url"] | Should -Be "http://{server}.swagger.io:{port}/v2" - $HS[0]["Description"] | Should -Be "petstore server" - $HS[0]["Variables"]["server"]["Description"] | Should -Be "No description provided" - $HS[0]["Variables"]["server"]["DefaultValue"] | Should -Be "petstore" - $HS[0]["Variables"]["server"]["EnumValues"] | Should -Be @("petstore", + $HS[1]["Url"] | Should -Be "http://{server}.swagger.io:{port}/v2" + $HS[1]["Description"] | Should -Be "petstore server" + $HS[1]["Variables"]["server"]["Description"] | Should -Be "No description provided" + $HS[1]["Variables"]["server"]["DefaultValue"] | Should -Be "petstore" + $HS[1]["Variables"]["server"]["EnumValues"] | Should -Be @("petstore", "qa-petstore", "dev-petstore") } 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 1 | Should -Be "http://petstore.swagger.io:80/v2" + Get-PSUrlFromHostSetting -Index 1 -Variables @{ "port" = "8080" } | Should -Be "http://petstore.swagger.io:8080/v2" #Get-PSUrlFromHostSetting -Index 2 | Should -Throw -ExceptionType ([RuntimeException]) #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"