From c377fdf62d261d1367b2f1637f17fa0a3af22da9 Mon Sep 17 00:00:00 2001 From: Elon Mallin Date: Sun, 12 Nov 2023 17:29:49 +0100 Subject: [PATCH] Fix powershell client Build.ps1 and *.psm1 error when there is a missing Model folder (#17025) * fix(powershell): make sure paths exists when building and importing module * chore(powershell): update sample psm1 and build.ps1 with path check --- .../src/main/resources/powershell/Build.ps1.mustache | 4 +++- .../main/resources/powershell/Org.OpenAPITools.psm1.mustache | 4 +++- samples/client/petstore/powershell/Build.ps1 | 4 +++- .../client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache b/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache index 6fed374afbd..be74a118037 100644 --- a/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache @@ -39,7 +39,9 @@ function Get-FunctionsToExport { } $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path -$FunctionPath = 'Api', 'Model', 'Client' | ForEach-Object {Join-Path "$ScriptDir\src\{{{packageName}}}\" $_} +$FunctionPath = 'Api', 'Model', 'Client' | Where-Object { + Join-Path "$ScriptDir\src\{{{packageName}}}\" $_ | Test-Path +} | ForEach-Object { Join-Path "$ScriptDir\src\{{{packageName}}}\" $_ } $Manifest = @{ Path = "$ScriptDir\src\{{{packageName}}}\{{{packageName}}}.psd1" diff --git a/modules/openapi-generator/src/main/resources/powershell/Org.OpenAPITools.psm1.mustache b/modules/openapi-generator/src/main/resources/powershell/Org.OpenAPITools.psm1.mustache index 32795eca376..feb7ee5ec66 100644 --- a/modules/openapi-generator/src/main/resources/powershell/Org.OpenAPITools.psm1.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/Org.OpenAPITools.psm1.mustache @@ -17,7 +17,9 @@ $Script:Configuration = [System.Collections.HashTable]@{} $Script:CmdletBindingParameters = @('Verbose','Debug','ErrorAction','WarningAction','InformationAction','ErrorVariable','WarningVariable','InformationVariable','OutVariable','OutBuffer','PipelineVariable') -'Api', 'Model', 'Client', 'Private' | Get-ChildItem -Path { +'Api', 'Model', 'Client', 'Private' | Where-Object { + Join-Path $PSScriptRoot $_ | Test-Path +} | Get-ChildItem -Path { Join-Path $PSScriptRoot $_ } -Filter '*.ps1' | ForEach-Object { Write-Debug "Importing file: $($_.BaseName)" diff --git a/samples/client/petstore/powershell/Build.ps1 b/samples/client/petstore/powershell/Build.ps1 index e15418c3aad..81c67431bdb 100644 --- a/samples/client/petstore/powershell/Build.ps1 +++ b/samples/client/petstore/powershell/Build.ps1 @@ -45,7 +45,9 @@ function Get-FunctionsToExport { } $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path -$FunctionPath = 'Api', 'Model', 'Client' | ForEach-Object {Join-Path "$ScriptDir\src\PSPetstore\" $_} +$FunctionPath = 'Api', 'Model', 'Client' | Where-Object { + Join-Path "$ScriptDir\src\PSPetstore\" $_ | Test-Path +} | ForEach-Object { Join-Path "$ScriptDir\src\PSPetstore\" $_ } $Manifest = @{ Path = "$ScriptDir\src\PSPetstore\PSPetstore.psd1" diff --git a/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 b/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 index 8b0bd5f780e..486b345ebc1 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 +++ b/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 @@ -23,7 +23,9 @@ $Script:Configuration = [System.Collections.HashTable]@{} $Script:CmdletBindingParameters = @('Verbose','Debug','ErrorAction','WarningAction','InformationAction','ErrorVariable','WarningVariable','InformationVariable','OutVariable','OutBuffer','PipelineVariable') -'Api', 'Model', 'Client', 'Private' | Get-ChildItem -Path { +'Api', 'Model', 'Client', 'Private' | Where-Object { + Join-Path $PSScriptRoot $_ | Test-Path +} | Get-ChildItem -Path { Join-Path $PSScriptRoot $_ } -Filter '*.ps1' | ForEach-Object { Write-Debug "Importing file: $($_.BaseName)"