From f327f01c19d8c84bdd576064b2c90146a173084c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 8 May 2020 20:13:01 +0800 Subject: [PATCH] Replace powershell generator with powershell-experimental generator (#6213) * replace powershell generator with powershell-experimental generator * add back samples * add back scripts * remove outdated script * update doc --- appveyor.yml | 2 +- .../powershell-experimental-petstore.sh | 32 - bin/openapi3/powershell-petstore.sh | 32 - bin/powershell-petstore.sh | 2 +- bin/windows/powershell-petsstore.bat | 10 - bin/windows/powershell-petstore.bat | 10 + docs/generators.md | 3 +- docs/generators/powershell.md | 103 ++- .../languages/PowerShellClientCodegen.java | 803 ++++++++++++++++-- .../org.openapitools.codegen.CodegenConfig | 1 - .../Build.ps1.mustache | 66 -- .../Org.OpenAPITools.psm1.mustache | 23 - .../powershell-experimental/README.mustache | 114 --- .../about_Org.OpenAPITools.help.txt.mustache | 27 - .../powershell-experimental/api.mustache | 235 ----- .../powershell-experimental/api_doc.mustache | 87 -- .../powershell-experimental/api_test.mustache | 15 - .../powershell-experimental/model.mustache | 107 --- .../model_doc.mustache | 29 - .../model_test.mustache | 15 - .../resources/powershell/Build.ps1.mustache | 38 +- .../Get-CommonParameters.mustache | 0 .../powershell/Get-CommonParameters.ps1 | 14 - .../powershell/Org.OpenAPITools.psm1.mustache | 34 +- .../Out-DebugParameter.mustache | 0 .../powershell/Out-DebugParameter.ps1 | 37 - .../main/resources/powershell/README.mustache | 94 +- .../main/resources/powershell/api.mustache | 229 ++++- .../api_client.mustache | 0 .../resources/powershell/api_doc.mustache | 98 +-- .../resources/powershell/api_test.mustache | 16 +- .../appveyor.mustache | 0 .../configuration.mustache | 0 .../http_signature_auth.mustache | 0 .../main/resources/powershell/model.mustache | 104 ++- .../resources/powershell/model_doc.mustache | 17 +- .../resources/powershell/model_test.mustache | 13 +- .../partial_header.mustache | 0 .../rsa_provider.mustache | 0 .../.openapi-generator-ignore | 23 - .../.openapi-generator/VERSION | 1 - .../powershell-experimental/Build.ps1 | 72 -- .../powershell-experimental/README.md | 120 --- .../powershell/.openapi-generator/VERSION | 2 +- samples/client/petstore/powershell/Build.ps1 | 42 +- samples/client/petstore/powershell/README.md | 110 ++- .../Test1.ps1 | 0 .../appveyor.yml | 0 .../docs/ApiResponse.md | 0 .../docs/Category.md | 0 .../docs/InlineObject.md | 0 .../docs/InlineObject1.md | 0 .../docs/Order.md | 0 .../docs/PSPetApi.md | 0 .../docs/PSStoreApi.md | 0 .../docs/PSUserApi.md | 0 .../docs/Pet.md | 0 .../docs/Tag.md | 0 .../docs/User.md | 0 .../plus.gif | Bin .../src/Org.OpenAPITools/API/PetApi.ps1 | 164 ---- .../src/Org.OpenAPITools/API/StoreApi.ps1 | 68 -- .../src/Org.OpenAPITools/API/UserApi.ps1 | 148 ---- .../Model/New-ApiResponse.ps1 | 25 - .../Org.OpenAPITools/Model/New-Category.ps1 | 21 - .../Model/New-InlineObject.ps1 | 21 - .../Model/New-InlineObject1.ps1 | 21 - .../src/Org.OpenAPITools/Model/New-Order.ps1 | 37 - .../src/Org.OpenAPITools/Model/New-Pet.ps1 | 37 - .../src/Org.OpenAPITools/Model/New-Tag.ps1 | 21 - .../src/Org.OpenAPITools/Model/New-User.ps1 | 45 - .../Org.OpenAPITools/Org.OpenAPITools.psd1 | 136 --- .../Org.OpenAPITools/Org.OpenAPITools.psm1 | 29 - .../Private/Get-CommonParameters.ps1 | 14 - .../Private/Out-DebugParameter.ps1 | 37 - .../en-US/about_Org.OpenAPITools.help.txt | 19 - .../src/PSPetstore/API/PSPetApi.ps1 | 0 .../src/PSPetstore/API/PSStoreApi.ps1 | 0 .../src/PSPetstore/API/PSUserApi.ps1 | 0 .../src/PSPetstore/Client/PSConfiguration.ps1 | 0 .../src/PSPetstore/Model/ApiResponse.ps1 | 0 .../src/PSPetstore/Model/Category.ps1 | 0 .../src/PSPetstore/Model/InlineObject.ps1 | 0 .../src/PSPetstore/Model/InlineObject1.ps1 | 0 .../src/PSPetstore/Model/Order.ps1 | 0 .../src/PSPetstore/Model/Pet.ps1 | 0 .../src/PSPetstore/Model/Tag.ps1 | 0 .../src/PSPetstore/Model/User.ps1 | 0 .../src/PSPetstore/PSPetstore.psd1 | 0 .../src/PSPetstore/PSPetstore.psm1 | 0 .../Private/Get-CommonParameters.ps1 | 0 .../PSPetstore/Private/Out-DebugParameter.ps1 | 0 .../src/PSPetstore/Private/PSApiClient.ps1 | 15 + .../en-US/about_PSPetstore.help.txt | 2 +- .../powershell/test/ApiResponseTest.ps1 | 2 - .../petstore/powershell/test/CategoryTest.ps1 | 2 - .../powershell/test/InlineObject1Test.ps1 | 2 - .../powershell/test/InlineObjectTest.ps1 | 2 - .../petstore/powershell/test/OrderTest.ps1 | 2 - .../petstore/powershell/test/PetApiTest.ps1 | 69 -- .../petstore/powershell/test/PetTest.ps1 | 2 - .../petstore/powershell/test/StoreApiTest.ps1 | 37 - .../petstore/powershell/test/TagTest.ps1 | 2 - .../petstore/powershell/test/UserApiTest.ps1 | 69 -- .../petstore/powershell/test/UserTest.ps1 | 2 - .../tests/Api/PSPetApi.Tests.ps1 | 0 .../tests/Api/PSStoreApi.Tests.ps1 | 0 .../tests/Api/PSUserApi.Tests.ps1 | 0 .../tests/Model/ApiResponse.Tests.ps1 | 0 .../tests/Model/Category.Tests.ps1 | 0 .../tests/Model/InlineObject.Tests.ps1 | 0 .../tests/Model/InlineObject1.Tests.ps1 | 0 .../tests/Model/Order.Tests.ps1 | 0 .../tests/Model/Pet.Tests.ps1 | 0 .../tests/Model/Tag.Tests.ps1 | 0 .../tests/Model/User.Tests.ps1 | 0 .../tests/Petstore.Tests.ps1 | 0 .../tests/plus.gif | Bin 118 files changed, 1423 insertions(+), 2408 deletions(-) delete mode 100755 bin/openapi3/powershell-experimental-petstore.sh delete mode 100755 bin/openapi3/powershell-petstore.sh delete mode 100644 bin/windows/powershell-petsstore.bat create mode 100755 bin/windows/powershell-petstore.bat delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/Build.ps1.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/Org.OpenAPITools.psm1.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/README.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/about_Org.OpenAPITools.help.txt.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/api_doc.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/api_test.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/model_doc.mustache delete mode 100644 modules/openapi-generator/src/main/resources/powershell-experimental/model_test.mustache rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/Get-CommonParameters.mustache (100%) delete mode 100644 modules/openapi-generator/src/main/resources/powershell/Get-CommonParameters.ps1 rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/Out-DebugParameter.mustache (100%) delete mode 100644 modules/openapi-generator/src/main/resources/powershell/Out-DebugParameter.ps1 rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/api_client.mustache (100%) rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/appveyor.mustache (100%) rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/configuration.mustache (100%) rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/http_signature_auth.mustache (100%) rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/partial_header.mustache (100%) rename modules/openapi-generator/src/main/resources/{powershell-experimental => powershell}/rsa_provider.mustache (100%) delete mode 100644 samples/client/petstore/powershell-experimental/.openapi-generator-ignore delete mode 100644 samples/client/petstore/powershell-experimental/.openapi-generator/VERSION delete mode 100644 samples/client/petstore/powershell-experimental/Build.ps1 delete mode 100644 samples/client/petstore/powershell-experimental/README.md rename samples/client/petstore/{powershell-experimental => powershell}/Test1.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/appveyor.yml (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/ApiResponse.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/Category.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/InlineObject.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/InlineObject1.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/Order.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/PSPetApi.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/PSStoreApi.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/PSUserApi.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/Pet.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/Tag.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/docs/User.md (100%) rename samples/client/petstore/{powershell-experimental => powershell}/plus.gif (100%) delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/API/PetApi.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/API/StoreApi.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/API/UserApi.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-ApiResponse.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Category.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject1.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Order.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Pet.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Tag.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-User.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psd1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psm1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Get-CommonParameters.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Out-DebugParameter.ps1 delete mode 100644 samples/client/petstore/powershell/src/Org.OpenAPITools/en-US/about_Org.OpenAPITools.help.txt rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/API/PSPetApi.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/API/PSStoreApi.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/API/PSUserApi.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Client/PSConfiguration.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/ApiResponse.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/Category.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/InlineObject.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/InlineObject1.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/Order.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/Pet.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/Tag.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Model/User.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/PSPetstore.psd1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/PSPetstore.psm1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Private/Get-CommonParameters.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Private/Out-DebugParameter.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/Private/PSApiClient.ps1 (91%) rename samples/client/petstore/{powershell-experimental => powershell}/src/PSPetstore/en-US/about_PSPetstore.help.txt (95%) delete mode 100644 samples/client/petstore/powershell/test/ApiResponseTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/CategoryTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/InlineObject1Test.ps1 delete mode 100644 samples/client/petstore/powershell/test/InlineObjectTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/OrderTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/PetApiTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/PetTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/StoreApiTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/TagTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/UserApiTest.ps1 delete mode 100644 samples/client/petstore/powershell/test/UserTest.ps1 rename samples/client/petstore/{powershell-experimental => powershell}/tests/Api/PSPetApi.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Api/PSStoreApi.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Api/PSUserApi.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/ApiResponse.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/Category.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/InlineObject.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/InlineObject1.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/Order.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/Pet.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/Tag.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Model/User.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/Petstore.Tests.ps1 (100%) rename samples/client/petstore/{powershell-experimental => powershell}/tests/plus.gif (100%) diff --git a/appveyor.yml b/appveyor.yml index 2f22bfc438b..008ac171f88 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -70,7 +70,7 @@ test_script: # test ps pestore - ps: | $ErrorActionPreference = "Stop" - cd samples\client\petstore\powershell-experimental\ + cd samples\client\petstore\powershell\ .\Build.ps1 Import-Module -Name '.\src\PSPetstore' $Result = Invoke-Pester -PassThru diff --git a/bin/openapi3/powershell-experimental-petstore.sh b/bin/openapi3/powershell-experimental-petstore.sh deleted file mode 100755 index 148fd2690e5..00000000000 --- a/bin/openapi3/powershell-experimental-petstore.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -while [ -h "$SCRIPT" ] ; do - ls=$(ls -ld "$SCRIPT") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=$(dirname "$SCRIPT")/"$link" - fi -done - -if [ ! -d "${APP_DIR}" ]; then - APP_DIR=$(dirname "$SCRIPT")/.. - APP_DIR=$(cd "${APP_DIR}"; pwd) -fi - -executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn -B clean package -fi - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/powershell-experimental -i modules/openapi-generator/src/test/resources/3_0/powershell/petstore.yaml -g powershell-experimental -o samples/client/petstore/powershell-experimental --additional-properties powershellGalleryUrl=https://www.powershellgallery.com/packages/PSPetstore,packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,packageName=PSPetstore,apiNamePrefix=PS,packageVersion=0.1.2,commonVerbs=Delete=Remove:Patch=Update $@" - -java ${JAVA_OPTS} -jar ${executable} ${ags} diff --git a/bin/openapi3/powershell-petstore.sh b/bin/openapi3/powershell-petstore.sh deleted file mode 100755 index fe5da4a22f6..00000000000 --- a/bin/openapi3/powershell-petstore.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -if [ ! -d "${APP_DIR}" ]; then - APP_DIR=`dirname "$SCRIPT"`/.. - APP_DIR=`cd "${APP_DIR}"; pwd` -fi - -executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn clean package -fi - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/powershell -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g powershell -o samples/client/petstore/powershell --additional-properties packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,csharpClientPath=\$ScriptDir\..\..\petstore\csharp\OpenAPIClient $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/powershell-petstore.sh b/bin/powershell-petstore.sh index dcad1f299ab..264e58d9f5b 100755 --- a/bin/powershell-petstore.sh +++ b/bin/powershell-petstore.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/powershell -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g powershell -o samples/client/petstore/powershell --additional-properties packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,csharpClientPath=\$ScriptDir\..\..\petstore\csharp\OpenAPIClient $@" +ags="generate -t modules/openapi-generator/src/main/resources/powershell -i modules/openapi-generator/src/test/resources/3_0/powershell/petstore.yaml -g powershell -o samples/client/petstore/powershell --additional-properties powershellGalleryUrl=https://www.powershellgallery.com/packages/PSPetstore,packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,packageName=PSPetstore,apiNamePrefix=PS,packageVersion=0.1.2,commonVerbs=Delete=Remove:Patch=Update $@" java ${JAVA_OPTS} -jar ${executable} ${ags} diff --git a/bin/windows/powershell-petsstore.bat b/bin/windows/powershell-petsstore.bat deleted file mode 100644 index ca7e08dcaa8..00000000000 --- a/bin/windows/powershell-petsstore.bat +++ /dev/null @@ -1,10 +0,0 @@ -set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar - -If Not Exist %executable% ( - mvn clean package -) - -REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties -set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g powershell -o samples\client\petstore\powershell --additional-properties packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,csharpClientPath=$ScriptDir\..\..\petstore\csharp\OpenAPIClient - -java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/powershell-petstore.bat b/bin/windows/powershell-petstore.bat new file mode 100755 index 00000000000..f5ea2c5f910 --- /dev/null +++ b/bin/windows/powershell-petstore.bat @@ -0,0 +1,10 @@ +set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g powershell -o samples\client\petstorep\powershell --additional-properties powershellGalleryUrl=https://www.powershellgallery.com/packages/PSPetstore,packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,packageName=PSPetstore,apiNamePrefix=PS,packageVersion=0.1.2,commonVerbs=Delete=Remove:Patch=Update + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/docs/generators.md b/docs/generators.md index cc730aab7d8..6d7800fd694 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -46,8 +46,7 @@ The following generators are available: * [ocaml](generators/ocaml.md) * [perl](generators/perl.md) * [php](generators/php.md) -* [powershell](generators/powershell.md) -* [powershell-experimental (beta)](generators/powershell-experimental.md) +* [powershell (beta)](generators/powershell.md) * [python](generators/python.md) * [python-experimental (experimental)](generators/python-experimental.md) * [r](generators/r.md) diff --git a/docs/generators/powershell.md b/docs/generators/powershell.md index ae0a0e5ce65..8d395f0f7ba 100644 --- a/docs/generators/powershell.md +++ b/docs/generators/powershell.md @@ -5,9 +5,12 @@ sidebar_label: powershell | Option | Description | Values | Default | | ------ | ----------- | ------ | ------- | -|csharpClientPath|Path to the C# API client generated by OpenAPI Generator, e.g. $ScriptDir\..\csharp\OpenAPIClient where $ScriptDir is the current directory. NOTE: you will need to generate the C# API client separately.| |$ScriptDir\csharp\OpenAPIClient| +|apiNamePrefix|Prefix that will be appended to all PS objects. Default: empty string. e.g. Pet => PSPet.| |null| +|commonVerbs|PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.| |null| |packageGuid|GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default.| |null| -|packageName|Client package name (e.g. org.openapitools.client).| |Org.OpenAPITools| +|packageName|Client package name (e.g. PSTwitter).| |PSOpenAPITools| +|packageVersion|Package version (e.g. 0.1.2).| |0.1.2| +|powershellGalleryUrl|URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).| |null| ## IMPORT MAPPING @@ -56,6 +59,7 @@ sidebar_label: powershell
  • Single
  • String
  • System.DateTime
  • +
  • System.IO.FileInfo
  • TimeSpan
  • UInt16
  • UInt32
  • @@ -68,37 +72,70 @@ sidebar_label: powershell ## RESERVED WORDS ## FEATURE SET diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java index cc2ba5bbd56..6c3625e1222 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java @@ -1,6 +1,5 @@ /* * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +18,12 @@ package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; +import org.openapitools.codegen.meta.GeneratorMetadata; +import org.openapitools.codegen.meta.Stability; import org.openapitools.codegen.meta.features.*; import org.openapitools.codegen.utils.ModelUtils; import org.openapitools.codegen.utils.ProcessUtils; @@ -39,10 +42,17 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}"; protected String sourceFolder = "src"; - protected String packageName = "Org.OpenAPITools"; - protected String csharpClientPath = "$ScriptDir\\csharp\\OpenAPIClient"; + protected String packageName = "PSOpenAPITools"; + protected String packageVersion = "0.1.2"; protected String apiDocPath = "docs/"; protected String modelDocPath = "docs/"; + protected String apiTestPath = "tests/Api"; + protected String modelTestPath = "tests/Model"; + protected HashSet nullablePrimitives; + protected String powershellGalleryUrl; + protected HashSet powershellVerbs; + protected Map commonVerbs; // verbs not in the official ps verb list but can be mapped to one of the verbs + protected HashSet methodNames; // store a list of method names to detect duplicates /** * Constructs an instance of `PowerShellClientCodegen`. @@ -71,16 +81,20 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo ParameterFeature.Cookie ) ); - - outputFolder = "generated-code" + File.separator + "powershell"; + + generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata) + .stability(Stability.BETA) + .build(); + + outputFolder = "generated-code" + File.separator + "powershell-expiermental"; modelTemplateFiles.put("model.mustache", ".ps1"); apiTemplateFiles.put("api.mustache", ".ps1"); modelTestTemplateFiles.put("model_test.mustache", ".ps1"); apiTestTemplateFiles.put("api_test.mustache", ".ps1"); - modelDocTemplateFiles.clear(); - apiDocTemplateFiles.clear(); + modelDocTemplateFiles.put("model_doc.mustache", ".md"); + apiDocTemplateFiles.put("api_doc.mustache", ".md"); embeddedTemplateDir = templateDir = "powershell"; - apiPackage = packageName + File.separator + "API"; + apiPackage = packageName + File.separator + "Api"; modelPackage = packageName + File.separator + "Model"; // https://blogs.msdn.microsoft.com/powershell/2010/01/07/how-objects-are-sent-to-and-from-remote-sessions/ @@ -107,44 +121,329 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo "Boolean", "Guid", "Uri", + "System.IO.FileInfo", "Version" )); - // https://richardspowershellblog.wordpress.com/2009/05/02/powershell-reserved-words/ - reservedWords = new HashSet(Arrays.asList( - "Begin", - "Break", - "Catch", - "Continue", - "Data", - "Do", - "Dynamicparam", - "Else", - "Elseif", - "End", + commonVerbs = new HashMap(); + + Map> verbMappings = new HashMap>(); + + // common + verbMappings.put("Add", Arrays.asList("Append", "Attach", "Concatenate", "Insert")); + verbMappings.put("Clear", Arrays.asList("Flush", "Erase", "Release", "Unmark", "Unset", "Nullify")); + verbMappings.put("Close", Arrays.asList()); + verbMappings.put("Copy", Arrays.asList("Duplicate", "Clone", "Replicate", "Sync")); + verbMappings.put("Enter", Arrays.asList("PushInto")); + verbMappings.put("Exit", Arrays.asList("PopOut")); + verbMappings.put("Find", Arrays.asList()); + verbMappings.put("Format", Arrays.asList()); + verbMappings.put("Get", Arrays.asList("Read", "Open", "Cat", "Type", "Dir", "Obtain", "Dump", "Acquire", "Examine", "Find", "Search")); + verbMappings.put("Hide", Arrays.asList("Block")); + verbMappings.put("Join", Arrays.asList("Combine", "Unite", "Connect", "Associate")); + verbMappings.put("Lock", Arrays.asList("RestrictSecure")); + verbMappings.put("Move", Arrays.asList("Transfer", "Name", "Migrate")); + verbMappings.put("New", Arrays.asList("Create", "Generate", "Build", "Make", "Allocate")); + verbMappings.put("Open", Arrays.asList()); + verbMappings.put("Optimize", Arrays.asList()); + verbMappings.put("Pop", Arrays.asList()); + verbMappings.put("Push", Arrays.asList()); + verbMappings.put("Redo", Arrays.asList()); + verbMappings.put("Remove", Arrays.asList("Clear", "Cut", "Dispose", "Discard", "Erase")); + verbMappings.put("Rename", Arrays.asList("Change")); + verbMappings.put("Reset", Arrays.asList()); + verbMappings.put("Search", Arrays.asList("FindLocate")); + verbMappings.put("Select", Arrays.asList("FindLocate")); + verbMappings.put("Set", Arrays.asList("Write", "Reset", "Assign", "Configure")); + verbMappings.put("Show", Arrays.asList("DisplayProduce")); + verbMappings.put("Skip", Arrays.asList("BypassJump")); + verbMappings.put("Split", Arrays.asList("parate")); + verbMappings.put("Step", Arrays.asList()); + verbMappings.put("Switch", Arrays.asList()); + verbMappings.put("Undo", Arrays.asList()); + verbMappings.put("Unlock", Arrays.asList("Release", "Unrestrict", "Unsecure")); + verbMappings.put("Watch", Arrays.asList()); + + // communication + verbMappings.put("Connect", Arrays.asList("JoinTelnet")); + verbMappings.put("Disconnect", Arrays.asList("BreakLogoff")); + verbMappings.put("Read", Arrays.asList("Acquire", "Prompt", "Get")); + verbMappings.put("Receive", Arrays.asList("Read", "Accept", "Peek")); + verbMappings.put("Send", Arrays.asList("Put", "Broadcast", "Mail", "Fax")); + verbMappings.put("Write", Arrays.asList("PutPrint")); + + // data + verbMappings.put("Backup", Arrays.asList(" Save", " Burn", " Replicate", "Sync")); + verbMappings.put("Checkpoint", Arrays.asList(" Diff")); + verbMappings.put("Compare", Arrays.asList(" Diff")); + verbMappings.put("Compress", Arrays.asList(" Compact")); + verbMappings.put("Convert", Arrays.asList(" Change", " Resize", "Resample")); + verbMappings.put("ConvertFrom", Arrays.asList(" Export", " Output", "Out")); + verbMappings.put("ConvertTo", Arrays.asList(" Import", " Input", "In")); + verbMappings.put("Dismount", Arrays.asList(" UnmountUnlink")); + verbMappings.put("Edit", Arrays.asList(" Change", " Update", "Modify")); + verbMappings.put("Expand", Arrays.asList(" ExplodeUncompress")); + verbMappings.put("Export", Arrays.asList(" ExtractBackup")); + verbMappings.put("Group", Arrays.asList(" Aggregate", " Arrange", " Associate", "Correlate")); + verbMappings.put("Import", Arrays.asList(" BulkLoadLoad")); + verbMappings.put("Initialize", Arrays.asList(" Erase", " Init", " Renew", " Rebuild", " Reinitialize", "Setup")); + verbMappings.put("Limit", Arrays.asList(" Quota")); + verbMappings.put("Merge", Arrays.asList(" CombineJoin")); + verbMappings.put("Mount", Arrays.asList(" Connect")); + verbMappings.put("Out", Arrays.asList()); + verbMappings.put("Publish", Arrays.asList(" Deploy", " Release", "Install")); + verbMappings.put("Restore", Arrays.asList(" Repair", " Return", " Undo", "Fix")); + verbMappings.put("Save", Arrays.asList()); + verbMappings.put("Sync", Arrays.asList(" Replicate", " Coerce", "Match")); + verbMappings.put("Unpublish", Arrays.asList(" Uninstall", " Revert", "Hide")); + verbMappings.put("Update", Arrays.asList(" Refresh", " Renew", " Recalculate", "Re-index")); + + // diagnostic + verbMappings.put("Debug", Arrays.asList("Diagnose")); + verbMappings.put("Measure", Arrays.asList("Calculate", "Determine", "Analyze")); + verbMappings.put("Ping", Arrays.asList()); + verbMappings.put("Repair", Arrays.asList("FixRestore")); + verbMappings.put("Resolve", Arrays.asList("ExpandDetermine")); + verbMappings.put("Test", Arrays.asList("Diagnose", "Analyze", "Salvage", "Verify")); + verbMappings.put("Trace", Arrays.asList("Track", "Follow", "Inspect", "Dig")); + + // lifecycle + verbMappings.put("Approve", Arrays.asList()); + verbMappings.put("Assert", Arrays.asList("Certify")); + verbMappings.put("Build", Arrays.asList()); + verbMappings.put("Complete", Arrays.asList()); + verbMappings.put("Confirm", Arrays.asList("Acknowledge", "Agree", "Certify", "Validate", "Verify")); + verbMappings.put("Deny", Arrays.asList("Block", "Object", "Refuse", "Reject")); + verbMappings.put("Deploy", Arrays.asList()); + verbMappings.put("Disable", Arrays.asList("HaltHide")); + verbMappings.put("Enable", Arrays.asList("StartBegin")); + verbMappings.put("Install", Arrays.asList("Setup")); + verbMappings.put("Invoke", Arrays.asList("RunStart")); + verbMappings.put("Register", Arrays.asList()); + verbMappings.put("Request", Arrays.asList()); + verbMappings.put("Restart", Arrays.asList("Recycle")); + verbMappings.put("Resume", Arrays.asList()); + verbMappings.put("Start", Arrays.asList("Launch", "Initiate", "Boot")); + verbMappings.put("Stop", Arrays.asList("End", "Kill", "Terminate", "Cancel")); + verbMappings.put("Submit", Arrays.asList("Post")); + verbMappings.put("Suspend", Arrays.asList("Pause")); + verbMappings.put("Uninstall", Arrays.asList()); + verbMappings.put("Unregister", Arrays.asList("Remove")); + verbMappings.put("Wait", Arrays.asList("SleepPause")); + + // security + verbMappings.put("Block", Arrays.asList("Prevent", "Limit", "Deny")); + verbMappings.put("Grant", Arrays.asList("AllowEnable")); + verbMappings.put("Protect", Arrays.asList("Encrypt", "Safeguard", "Seal")); + verbMappings.put("Revoke", Arrays.asList("RemoveDisable")); + verbMappings.put("Unblock", Arrays.asList("ClearAllow")); + verbMappings.put("Unprotect", Arrays.asList("DecryptUnseal")); + + // other + verbMappings.put("Use", Arrays.asList()); + + for (Map.Entry> entry : verbMappings.entrySet()) { + // loop through each verb in the list + for (String verb : entry.getValue()) { + if (verbMappings.containsKey(verb)) { + // the verb to be mapped is also a common verb, do nothing + LOGGER.debug("verbmapping: skipped {}", verb); + } else { + commonVerbs.put(verb, entry.getKey()); + LOGGER.debug("verbmapping: adding {} => {}", verb, entry.getKey()); + } + } + } + + powershellVerbs = new HashSet(Arrays.asList( + "Add", + "Clear", + "Close", + "Copy", + "Enter", "Exit", - "Filter", - "Finally", - "For", - "Foreach", - "From", - "Function", - "If", - "In", - "Param", - "Process", - "Return", + "Find", + "Format", + "Get", + "Hide", + "Join", + "Lock", + "Move", + "New", + "Open", + "Optimize", + "Pop", + "Push", + "Redo", + "Remove", + "Rename", + "Reset", + "Search", + "Select", + "Set", + "Show", + "Skip", + "Split", + "Step", "Switch", - "Throw", - "Trap", - "Try", - "Until", - "While", - "Local", - "Private", - "Where" + "Undo", + "Unlock", + "Watch", + "Connect", + "Disconnect", + "Read", + "Receive", + "Send", + "Write", + "Backup", + "Checkpoint", + "Compare", + "Compress", + "Convert", + "ConvertFrom", + "ConvertTo", + "Dismount", + "Edit", + "Expand", + "Export", + "Group", + "Import", + "Initialize", + "Limit", + "Merge", + "Mount", + "Out", + "Publish", + "Restore", + "Save", + "Sync", + "Unpublish", + "Update", + "Debug", + "Measure", + "Ping", + "Repair", + "Resolve", + "Test", + "Trace", + "Approve", + "Assert", + "Build", + "Complete", + "Confirm", + "Deny", + "Deploy", + "Disable", + "Enable", + "Install", + "Invoke", + "Register", + "Request", + "Restart", + "Resume", + "Start", + "Stop", + "Submit", + "Suspend", + "Uninstall", + "Unregister", + "Wait", + "Block", + "Grant", + "Protect", + "Revoke", + "Unblock", + "Unprotect", + "Use" )); + methodNames = new HashSet(); + + nullablePrimitives = new HashSet(Arrays.asList( + "System.Nullable[Byte]", + "System.Nullable[SByte]", + "System.Nullable[Int16]", + "System.Nullable[Int32]", + "System.Nullable[Int64]", + "System.Nullable[UInt16]", + "System.Nullable[UInt32]", + "System.Nullable[UInt64]", + "System.Nullable[Decimal]", + "System.Nullable[Single]", + "System.Nullable[Double]", + "System.Nullable[Boolean]" + )); + + // list of reserved words - must be in lower case + reservedWords = new HashSet(Arrays.asList( + // https://richardspowershellblog.wordpress.com/2009/05/02/powershell-reserved-words/ + "begin", + "break", + "catch", + "continue", + "data", + "do", + "dynamicparam", + "else", + "elseif", + "end", + "exit", + "filter", + "finally", + "for", + "foreach", + "from", + "function", + "if", + "in", + "param", + "process", + "return", + "switch", + "throw", + "trap", + "try", + "until", + "while", + "local", + "private", + "where", + // special variables + "args", + "consolefilename", + "error", + "event", + "eventargs", + "eventsubscriber", + "executioncontext", + "false", + "foreach", + "home", + "host", + "input", + "lastexitcode", + "matches", + "myinvocation", + "nestedpromptlevel", + "null", + "pid", + "profile", + "pscmdlet", + "pscommandpath", + "psculture", + "psdebugcontext", + "pshome", + "psitem", + "psscriptroot", + "pssenderinfo", + "psuiculture", + "psversiontable", + "sender", + "shellid", + "stacktrace", + "this", + "true" + )); defaultIncludes = new HashSet(Arrays.asList( "Byte", @@ -169,6 +468,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo "Boolean", "Guid", "Uri", + "System.IO.FileInfo", "Version" )); @@ -180,18 +480,24 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo typeMapping.put("long", "Int64"); typeMapping.put("double", "Double"); typeMapping.put("number", "Decimal"); - typeMapping.put("date-time", "System.DateTime"); + typeMapping.put("object", "System.Collections.Hashtable"); + typeMapping.put("file", "System.IO.FileInfo"); + typeMapping.put("ByteArray", "System.Byte[]"); + typeMapping.put("binary", "System.IO.FileInfo"); typeMapping.put("date", "System.DateTime"); - typeMapping.put("file", "String"); - typeMapping.put("object", "String"); - typeMapping.put("binary", "String"); + typeMapping.put("date-time", "System.DateTime"); typeMapping.put("Date", "System.DateTime"); typeMapping.put("DateTime", "System.DateTime"); + typeMapping.put("UUID", "String"); + typeMapping.put("URI", "String"); cliOptions.clear(); - cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Client package name (e.g. org.openapitools.client).").defaultValue(this.packageName)); + cliOptions.add(new CliOption("powershellGalleryUrl", "URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).")); + cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Client package name (e.g. PSTwitter).").defaultValue(this.packageName)); + cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Package version (e.g. 0.1.2).").defaultValue(this.packageVersion)); cliOptions.add(new CliOption(CodegenConstants.OPTIONAL_PROJECT_GUID, "GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default.")); - cliOptions.add(new CliOption("csharpClientPath", "Path to the C# API client generated by OpenAPI Generator, e.g. $ScriptDir\\..\\csharp\\OpenAPIClient where $ScriptDir is the current directory. NOTE: you will need to generate the C# API client separately.").defaultValue(this.csharpClientPath)); + cliOptions.add(new CliOption(CodegenConstants.API_NAME_PREFIX, "Prefix that will be appended to all PS objects. Default: empty string. e.g. Pet => PSPet.")); + cliOptions.add(new CliOption("commonVerbs", "PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.")); } @@ -204,17 +510,17 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo } public String getHelp() { - return "Generates a PowerShell API client (beta). (The dependency C# API client needs to be generated separately."; + return "Generates a PowerShell API client (beta)"; } public void setPackageName(String packageName) { this.packageName = packageName; - this.apiPackage = packageName + File.separator + "API"; + this.apiPackage = packageName + File.separator + "Api"; this.modelPackage = packageName + File.separator + "Model"; } - public void setCsharpClientPath(String csharpClientPath) { - this.csharpClientPath = csharpClientPath; + public void setPackageVersion(String packageVersion) { + this.packageVersion = packageVersion; } public void setSourceFolder(String sourceFolder) { @@ -225,14 +531,36 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo this.packageGuid = packageGuid; } + public void setPowershellGalleryUrl(String powershellGalleryUrl) { + this.powershellGalleryUrl = powershellGalleryUrl; + } + @Override public void processOpts() { super.processOpts(); + if (StringUtils.isEmpty(System.getenv("POWERSHELL_POST_PROCESS_FILE"))) { + LOGGER.info("Environment variable POWERSHELL_POST_PROCESS_FILE not defined so the PowerShell code may not be properly formatted. To define it, try 'export POWERSHELL_POST_PROCESS_FILE=\"Edit-DTWBeautifyScript\"'"); + LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI)."); + } + + if (additionalProperties.containsKey("powershellGalleryUrl")) { + setPowershellGalleryUrl((String) additionalProperties.get("powershellGalleryUrl")); + } else { + additionalProperties.put("powershellGalleryUrl", powershellGalleryUrl); + } + + if (StringUtils.isNotBlank(powershellGalleryUrl)) { + // get the last segment of the URL + // e.g. https://www.powershellgallery.com/packages/PSTwitter => PSTwitter + additionalProperties.put("powershellGalleryId", powershellGalleryUrl.replaceFirst(".*/([^/?]+).*", "$1")); + } + if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_GUID)) { setPackageGuid((String) additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_GUID)); + } else { + additionalProperties.put("packageGuid", packageGuid); } - additionalProperties.put("packageGuid", packageGuid); if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { this.setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); @@ -240,10 +568,23 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName); } - if (additionalProperties.containsKey("csharpClientPath")) { - this.setCsharpClientPath((String) additionalProperties.get("csharpClientPath")); + if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) { + this.setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION)); } else { - additionalProperties.put("csharpClientPath", csharpClientPath); + additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion); + } + + if (additionalProperties.containsKey("commonVerbs")) { + String[] entries = ((String)additionalProperties.get("commonVerbs")).split(":"); + for (String entry : entries) { + String[] pair = entry.split("="); + if (pair.length == 2) { + commonVerbs.put(pair[0], pair[1]); + LOGGER.debug("Add commonVerbs: {} => {}", pair[0], pair[1]); + } else { + LOGGER.error("Failed to parse commonVerbs: {}", entry); + } + } } if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) { @@ -267,15 +608,47 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo supportingFiles.add(new SupportingFile("Org.OpenAPITools.psm1.mustache", infrastructureFolder, packageName + ".psm1")); + // client/configuration + supportingFiles.add(new SupportingFile("configuration.mustache", infrastructureFolder + "Client", apiNamePrefix + "Configuration.ps1")); + // private - supportingFiles.add(new SupportingFile("Get-CommonParameters.ps1", infrastructureFolder + File.separator + "Private" + File.separator, "Get-CommonParameters.ps1")); - supportingFiles.add(new SupportingFile("Out-DebugParameter.ps1", infrastructureFolder + File.separator + "Private" + File.separator, "Out-DebugParameter.ps1")); + supportingFiles.add(new SupportingFile("api_client.mustache", infrastructureFolder + "Private", apiNamePrefix + "ApiClient.ps1")); + supportingFiles.add(new SupportingFile("Get-CommonParameters.mustache", infrastructureFolder + File.separator + "Private" + File.separator, "Get-CommonParameters.ps1")); + supportingFiles.add(new SupportingFile("Out-DebugParameter.mustache", infrastructureFolder + File.separator + "Private" + File.separator, "Out-DebugParameter.ps1")); + supportingFiles.add(new SupportingFile("http_signature_auth.mustache", infrastructureFolder + "Private", apiNamePrefix + "HttpSignatureAuth.ps1")); + supportingFiles.add(new SupportingFile("rsa_provider.mustache", infrastructureFolder + "Private", apiNamePrefix + "RSAEncryptionProvider.cs")); + // en-US supportingFiles.add(new SupportingFile("about_Org.OpenAPITools.help.txt.mustache", infrastructureFolder + File.separator + "en-US" + File.separator + "about_" + packageName + ".help.txt")); + // appveyor + supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml")); } + @SuppressWarnings("static-method") + @Override + public String escapeText(String input) { + + if (input == null) { + return input; + } + + // remove \t, \n, \r + // replace \ with \\ + // replace " with \" + // outter unescape to retain the original multi-byte characters + // finally escalate characters avoiding code injection + return escapeUnsafeCharacters( + StringEscapeUtils.unescapeJava( + StringEscapeUtils.escapeJava(input) + .replace("\\/", "/")) + .replaceAll("[\\t\\n\\r]", " ") + .replace("\\", "\\\\") + .replace("\"", "\"\"")); + + } + @Override public String escapeUnsafeCharacters(String input) { return input.replace("#>", "#_>").replace("<#", "<_#"); @@ -287,9 +660,19 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo return input.replace("\"", ""); } + @Override + public String toApiTestFilename(String name) { + return toApiFilename(name) + ".Tests"; + } + + @Override + public String toModelTestFilename(String name) { + return toModelFilename(name) + ".Tests"; + } + @Override public String apiTestFileFolder() { - return (outputFolder + "/test").replace('/', File.separatorChar); + return (outputFolder + "/" + apiTestPath).replace('/', File.separatorChar); } @Override @@ -304,7 +687,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo @Override public String modelTestFileFolder() { - return (outputFolder + "/test").replace('/', File.separatorChar); + return (outputFolder + "/" + modelTestPath).replace('/', File.separatorChar); } @Override @@ -320,7 +703,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo @Override public String escapeReservedWord(String name) { - return "_" + name; + return "Var" + name; } /** @@ -340,29 +723,29 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo name = name + "_" + modelNameSuffix; } - name = sanitizeName(name); + // camelize the model name + // phone_number => PhoneNumber + name = camelize(sanitizeName(name)); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); - name = "model_" + name; // e.g. return => ModelReturn (after camelize) + LOGGER.warn(name + " (reserved word or special variable name) cannot be used as model name. Renamed to " + camelize("model_" + name)); + name = camelize("model_" + name); // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); - name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) + name = camelize("model_" + name); // e.g. 200Response => Model200Response (after camelize) } - // camelize the model name - // phone_number => PhoneNumber - return camelize(name); + return name; } @Override public String toModelFilename(String name) { // should be the same as the model name - return "New-" + toModelName(name); + return toModelName(name); } /** @@ -403,11 +786,9 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo Schema inner = ap.getItems(); return getTypeDeclaration(inner) + "[]"; } else if (ModelUtils.isMapSchema(p)) { - Schema inner = ModelUtils.getAdditionalProperties(p); - // TODO not sure if the following map/hash declaration is correct - return "{String, " + getTypeDeclaration(inner) + "}"; + return "System.Collections.Hashtable"; } else if (!languageSpecificPrimitives.contains(getSchemaType(p))) { - return packageName + ".Model." + super.getTypeDeclaration(p); + return super.getTypeDeclaration(p); } return super.getTypeDeclaration(p); } @@ -419,25 +800,61 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo throw new RuntimeException("Empty method name (operationId) not allowed"); } - // method name cannot use reserved keyword, e.g. return - if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); - operationId = "call_" + operationId; - } + return sanitizeName(operationId); + } - return camelize(sanitizeName(operationId)); + @Override + public String toParamName(String name) { + return toVarName(name); } @Override public Map postProcessOperationsWithModels(Map objs, List allModels) { Map operations = (Map) objs.get("operations"); + HashMap modelMaps = new HashMap(); + HashMap processedModelMaps = new HashMap(); + + for (Object o : allModels) { + HashMap h = (HashMap) o; + CodegenModel m = (CodegenModel) h.get("model"); + modelMaps.put(m.classname, m); + } + List operationList = (List) operations.get("operation"); for (CodegenOperation op : operationList) { int index = 0; for (CodegenParameter p : op.allParams) { + p.vendorExtensions.put("x-powershell-data-type", getPSDataType(p)); + p.vendorExtensions.put("x-powershell-example", constructExampleCode(p, modelMaps, processedModelMaps)); p.vendorExtensions.put("x-index", index); index++; } + + if (!op.vendorExtensions.containsKey("x-powershell-method-name")) { // x-powershell-method-name not set + String methodName = toMethodName(op.operationId); + op.vendorExtensions.put("x-powershell-method-name", methodName); + op.vendorExtensions.put("x-powershell-method-name-lowercase", methodName); + } else { + op.vendorExtensions.put("x-powershell-method-name-lowercase", ((String) op.vendorExtensions.get("x-powershell-method-name")).toLowerCase(Locale.ROOT)); + } + + // detect duplicated method name + if (methodNames.contains(op.vendorExtensions.get("x-powershell-method-name"))) { + LOGGER.error("Duplicated method name found: {}", op.vendorExtensions.get("x-powershell-method-name")); + } else { + methodNames.add(op.vendorExtensions.get("x-powershell-method-name")); + } + + if (op.produces != null && op.produces.size() > 1) { + op.vendorExtensions.put("x-powershell-select-accept", true); + } + } + + processedModelMaps.clear(); + for (CodegenOperation operation : operationList) { + for (CodegenParameter cp : operation.allParams) { + cp.vendorExtensions.put("x-powershell-example", constructExampleCode(cp, modelMaps, processedModelMaps)); + } } return objs; @@ -448,7 +865,241 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo List models = (List) objs.get("models"); // add x-index to properties ProcessUtils.addIndexToProperties(models); + + // add x-data-type to store powershell type + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + + for (CodegenProperty cp : cm.allVars) { + cp.vendorExtensions.put("x-powershell-data-type", getPSDataType(cp)); + } + } + return objs; } + @Override + public String toVarName(String name) { + // sanitize name + name = sanitizeName(name); + + // camelize the variable name + // pet_id => PetId + name = camelize(name); + + // for reserved word or word starting with number, append _ + if (isReservedWord(name) || name.matches("^\\d.*")) { + LOGGER.warn(name + " (reserved word or special variable name) cannot be used in naming. Renamed to " + escapeReservedWord(name)); + name = escapeReservedWord(name); + } + + return name; + } + + private String constructExampleCode(CodegenParameter codegenParameter, HashMap modelMaps, HashMap processedModelMap) { + if (codegenParameter.isListContainer) { // array + return "@(" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + ")"; + } else if (codegenParameter.isMapContainer) { // TODO: map, file type + return "@{ \"Key\" = \"Value\" }"; + } else if (languageSpecificPrimitives.contains(codegenParameter.dataType) || + nullablePrimitives.contains(codegenParameter.dataType)) { // primitive type + if ("String".equals(codegenParameter.dataType) || "Character".equals(codegenParameter.dataType)) { + if (StringUtils.isEmpty(codegenParameter.example)) { + return "\"" + codegenParameter.example + "\""; + } else { + return "\"" + codegenParameter.paramName + "_example\""; + } + } else if ("Boolean".equals(codegenParameter.dataType) || + "System.Nullable[Boolean]".equals(codegenParameter.dataType)) { // boolean + if (Boolean.parseBoolean(codegenParameter.example)) { + return "true"; + } else { + return "false"; + } + } else if ("URL".equals(codegenParameter.dataType)) { // URL + return "URL(string: \"https://example.com\")!"; + } else if ("System.DateTime".equals(codegenParameter.dataType)) { // datetime or date + return "Get-Date"; + } else { // numeric + if (StringUtils.isEmpty(codegenParameter.example)) { + return codegenParameter.example; + } else { + return "987"; + } + } + } else { // model + // look up the model + if (modelMaps.containsKey(codegenParameter.dataType)) { + return constructExampleCode(modelMaps.get(codegenParameter.dataType), modelMaps, processedModelMap); + } else { + //LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenParameter.dataType); + return "TODO"; + } + } + } + + private String constructExampleCode(CodegenProperty codegenProperty, HashMap modelMaps, HashMap processedModelMap) { + if (codegenProperty.isListContainer) { // array + return "@(" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + ")"; + } else if (codegenProperty.isMapContainer) { // map + return "\"TODO\""; + } else if (languageSpecificPrimitives.contains(codegenProperty.dataType) || // primitive type + nullablePrimitives.contains(codegenProperty.dataType)) { // nullable primitive type + if ("String".equals(codegenProperty.dataType)) { + if (StringUtils.isEmpty(codegenProperty.example)) { + return "\"" + codegenProperty.example + "\""; + } else { + return "\"" + codegenProperty.name + "_example\""; + } + } else if ("Boolean".equals(codegenProperty.dataType) || + "System.Nullable[Boolean]".equals(codegenProperty.dataType)) { // boolean + if (Boolean.parseBoolean(codegenProperty.example)) { + return "$true"; + } else { + return "$false"; + } + } else if ("URL".equals(codegenProperty.dataType)) { // URL + return "URL(string: \"https://example.com\")!"; + } else if ("System.DateTime".equals(codegenProperty.dataType)) { // datetime or date + return "Get-Date"; + } else { // numeric + if (StringUtils.isEmpty(codegenProperty.example)) { + return codegenProperty.example; + } else { + return "123"; + } + } + } else { + // look up the model + if (modelMaps.containsKey(codegenProperty.dataType)) { + return constructExampleCode(modelMaps.get(codegenProperty.dataType), modelMaps, processedModelMap); + } else { + //LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenProperty.dataType); + return "\"TODO\""; + } + } + } + + private String constructExampleCode(CodegenModel codegenModel, HashMap modelMaps, HashMap processedModelMap) { + String example; + + // break infinite recursion. Return, in case a model is already processed in the current context. + String model = codegenModel.name; + if (processedModelMap.containsKey(model)) { + int count = processedModelMap.get(model); + if (count == 1) { + processedModelMap.put(model, 2); + } else if (count == 2) { + return ""; + } else { + throw new RuntimeException("Invalid count when constructing example: " + count); + } + } else { + processedModelMap.put(model, 1); + } + + example = "(Initialize-" + codegenModel.name; + List propertyExamples = new ArrayList<>(); + for (CodegenProperty codegenProperty : codegenModel.allVars) { + propertyExamples.add("-" + codegenProperty.name + " " + constructExampleCode(codegenProperty, modelMaps, processedModelMap)); + } + example += StringUtils.join(propertyExamples, " "); + example += ")"; + return example; + } + + private String getPSDataType(CodegenProperty cp) { + String dataType; + if (cp.isPrimitiveType) { + dataType = cp.dataType; + if (!(cp.isString || cp.isFile || cp.isContainer) + && (cp.isNullable || !cp.required)) { + dataType = "System.Nullable[" + dataType + "]"; + } + return dataType; + } else if (cp.isListContainer) { // array + return getPSDataType(cp.items) + "[]"; + } else if (cp.isMapContainer) { // map + return "System.Collections.Hashtable"; + } else { // model + return "PSCustomObject"; + } + } + + private String getPSDataType(CodegenParameter cp) { + String dataType; + if (cp.isPrimitiveType) { + dataType = cp.dataType; + if (!(cp.isString || cp.isFile || cp.isContainer) + && (cp.isNullable || !cp.required)) { + dataType = "System.Nullable[" + dataType + "]"; + } + return dataType; + } else if (cp.isListContainer) { // array + return getPSDataType(cp.items) + "[]"; + } else if (cp.isMapContainer) { // map + return "System.Collections.Hashtable"; + } else { // model + return "PSCustomObject"; + } + } + + private String toMethodName(String operationId) { + String methodName = camelize(operationId); + + // check if method name starts with powershell verbs + for (String verb : (HashSet) powershellVerbs) { + if (methodName.startsWith(verb)) { + methodName = verb + "-" + apiNamePrefix + methodName.substring(verb.length()); + LOGGER.info("Naming the method using the PowerShell verb: {} => {}", operationId, methodName); + return methodName; + } + } + + for (Map.Entry entry : commonVerbs.entrySet()) { + if (methodName.startsWith(entry.getKey())) { + methodName = entry.getValue() + "-" + apiNamePrefix + methodName.substring(entry.getKey().length()); + LOGGER.info("Naming the method by mapping the common verbs (e.g. Create, Change) to PS verbs: {} => {}", operationId, methodName); + return methodName; + } + } + + // not using powershell verb + return "Invoke-" + apiNamePrefix + methodName; + } + + @Override + public void postProcessFile(File file, String fileType) { + if (file == null) { + return; + } + String powershellPostProcessFile = System.getenv("POWERSHELL_POST_PROCESS_FILE"); + if (StringUtils.isEmpty(powershellPostProcessFile)) { + return; // skip if POWERSHELL_POST_PROCESS_FILE env variable is not defined + } + + // only process files with ps extension + if ("ps".equals(FilenameUtils.getExtension(file.toString()))) { + String command = powershellPostProcessFile + " " + file.toString(); + try { + Process p = Runtime.getRuntime().exec(command); + int exitValue = p.waitFor(); + if (exitValue != 0) { + LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue); + } else { + LOGGER.info("Successfully executed: " + command); + } + } catch (Exception e) { + LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage()); + } + } + + } + + @Override + public String toRegularExpression(String pattern) { + return escapeText(pattern); + } + } diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index 8e2db93db51..9b3b68c28d7 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -84,7 +84,6 @@ org.openapitools.codegen.languages.PhpSilexServerCodegen org.openapitools.codegen.languages.PhpSymfonyServerCodegen org.openapitools.codegen.languages.PhpZendExpressivePathHandlerServerCodegen org.openapitools.codegen.languages.PowerShellClientCodegen -org.openapitools.codegen.languages.PowerShellExperimentalClientCodegen org.openapitools.codegen.languages.ProtobufSchemaCodegen org.openapitools.codegen.languages.PythonClientCodegen org.openapitools.codegen.languages.PythonClientExperimentalCodegen diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/Build.ps1.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/Build.ps1.mustache deleted file mode 100644 index ed875bc5e82..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/Build.ps1.mustache +++ /dev/null @@ -1,66 +0,0 @@ -{{> partial_header}} -function Get-FunctionsToExport { - [CmdletBinding()] - Param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] - [ValidateNotNullOrEmpty()] - [Alias('FullName')] - $Path - ) - - Process { - $Token = $null - $ParserErr = $null - - $Ast = [System.Management.Automation.Language.Parser]::ParseFile( - $Path, - [ref]$Token, - [ref]$ParserErr - ) - - if ($ParserErr) { - throw $ParserErr - } else { - foreach ($name in 'Begin', 'Process', 'End') { - foreach ($Statement in $Ast."${name}Block".Statements) { - if ( - [String]::IsNullOrWhiteSpace($Statement.Name) -or - $Statement.Extent.ToString() -notmatch - ('function\W+{0}' -f $Statement.Name) - ) { - continue - } - - $Statement.Name - } - } - } - } -} - -$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path -$FunctionPath = 'Api', 'Model', 'Client' | ForEach-Object {Join-Path "$ScriptDir\src\{{{packageName}}}\" $_} - -$Manifest = @{ - Path = "$ScriptDir\src\{{{packageName}}}\{{{packageName}}}.psd1" - - Author = 'OpenAPI Generator Team' - CompanyName = 'openapitools.org' - Description = '{{{packageName}}} - the PowerShell module for {{{appName}}}' - - ModuleVersion = '{{{packageVersion}}}' - - RootModule = '{{{packageName}}}.psm1' - Guid = '{{packageGuid}}' # Has to be static, otherwise each new build will be considered different module - - PowerShellVersion = '3.0' - - FunctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-FunctionsToExport - - VariablesToExport = @() - AliasesToExport = @() - CmdletsToExport = @() - -} - -New-ModuleManifest @Manifest diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/Org.OpenAPITools.psm1.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/Org.OpenAPITools.psm1.mustache deleted file mode 100644 index ce575233bb8..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/Org.OpenAPITools.psm1.mustache +++ /dev/null @@ -1,23 +0,0 @@ -{{>partial_header}} -#region Import functions - -# set $ErrorActionPreference to 'Stop' globally -$ErrorActionPreference = 'Stop' - -# store the API client's configuration -$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 { - Join-Path $PSScriptRoot $_ -} -Filter '*.ps1' | ForEach-Object { - Write-Debug "Importing file: $($_.BaseName)" - try { - . $_.FullName - } catch { - Write-Error -Message "Failed to import function $($_.Fullname): $_" - } -} - -#endregion diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/README.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/README.mustache deleted file mode 100644 index 357274b6543..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/README.mustache +++ /dev/null @@ -1,114 +0,0 @@ -# {{packageName}} - the PowerShell module for the {{appName}} - -{{#appDescriptionWithNewLines}} -{{{appDescriptionWithNewLines}}} - -{{/appDescriptionWithNewLines}} -This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - -- API version: {{appVersion}} -- SDK version: {{packageVersion}} -{{^hideGenerationTimestamp}} -- Build date: {{generatedDate}} -{{/hideGenerationTimestamp}} -- Build package: {{generatorClass}} -{{#infoUrl}} - For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) -{{/infoUrl}} - - -## Frameworks supported -- PowerShell 5.0 or later - - -## Dependencies - - -## Installation - -{{#powershellGalleryUrl}} -To install from PowerShell Gallery ({{{powershellGalleryUrl}}}) -```powershell -Import-Module -Name {{{powershellGalleryId}}} -Verbose -``` -{{/powershellGalleryUrl}} - -To install from the source, run the following command to build and install the PowerShell module locally: -```powershell -Build.ps1 -Import-Module -Name '.\src\{{{packageName}}}' -Verbose -``` - -To avoid function name collision, one can use `-Prefix`, e.g. `Import-Module -Name '.\src\{{{packageName}}}' -Prefix prefix` - -To uninstall the module, simply run: -```powershell -Remove-Module -FullyQualifiedName @{ModuleName = "{{{packageName}}}"; ModuleVersion = "{{{packageVersion}}}"} -``` - - -## Tests - -To install and run `Pester`, please execute the following commands in the terminal: - -```powershell -Install-module -name Pester -force - -Invoker-Pester -``` - -For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debugging and disable it with `$DebugPreference = 'SilentlyContinue'` when done with the troubleshooting. - -## Documentation for API Endpoints - -All URIs are relative to *{{{basePath}}}* - -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{vendorExtensions.x-powershell-method-name}}**]({{apiDocPath}}{{classname}}.md#{{vendorExtensions.x-powershell-method-name-lowercase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}} -{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} - -## Documentation for Models - -{{#modelPackage}} -{{#models}}{{#model}} - [{{{modelPackage}}}.{{{classname}}}]({{modelDocPath}}{{{classname}}}.md) -{{/model}}{{/models}} -{{/modelPackage}} -{{^modelPackage}} -No model defined in this package -{{/modelPackage}} - -## Documentation for Authorization - -{{^authMethods}} -All endpoints do not require authorization. -{{/authMethods}} -{{#authMethods}} -{{#last}} -Authentication schemes defined for the API: -{{/last}} -{{/authMethods}} -{{#authMethods}} - -### {{name}} - -{{#isApiKey}}- **Type**: API key - -- **API key parameter name**: {{keyParamName}} -- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} -{{/isApiKey}} -{{#isBasic}} - -- **Type**: HTTP basic authentication -{{/isBasic}} -{{#isOAuth}} - -- **Type**: OAuth -- **Flow**: {{flow}} -- **Authorization URL**: {{authorizationUrl}} -- **Scopes**: {{^scopes}}N/A{{/scopes}} -{{#scopes}} - {{scope}}: {{description}} -{{/scopes}} -{{/isOAuth}} - -{{/authMethods}} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/about_Org.OpenAPITools.help.txt.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/about_Org.OpenAPITools.help.txt.mustache deleted file mode 100644 index 10b226f136e..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/about_Org.OpenAPITools.help.txt.mustache +++ /dev/null @@ -1,27 +0,0 @@ -PSTOPIC - about_{{{packageName}}} - -SHORT DESCRIPTION - {{{packageName}}} - the PowerShell module for the {{{appName}}} - -LONG DESCRIPTION -{{#appDescription}} - {{{appDescription}}} - -{{/appDescription}} - This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - - - API version: {{appVersion}} - - SDK version: {{packageVersion}} - {{^hideGenerationTimestamp}} - - Build date: {{generatedDate}} - {{/hideGenerationTimestamp}} - - Build package: {{{generatorClass}}} - {{#infoUrl}} - For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) - {{/infoUrl}} - - Frameworks supported: - - * PowerShell 3.0+ - * .NET 4.0 or later diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache deleted file mode 100644 index e89e0bd91cc..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache +++ /dev/null @@ -1,235 +0,0 @@ -{{> partial_header}} -{{#operations}} -{{#operation}} -<# -.SYNOPSIS - -{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}} - -.DESCRIPTION - -{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} - -{{#allParams}} -.PARAMETER {{{paramName}}} -{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} - -{{/allParams}} -{{#vendorExtensions.x-powershell-select-accept}} -.PARAMETER ReturnType - -Select the return type (optional): {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}} - -{{/vendorExtensions.x-powershell-select-accept}} -.PARAMETER WithHttpInfo - -A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response - -.OUTPUTS - -{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}None{{/returnType}} -#> -function {{{vendorExtensions.x-powershell-method-name}}} { - [CmdletBinding()] - Param ( - {{#allParams}} - [Parameter(Position = {{vendorExtensions.x-index}}{{#-first}}, ValueFromPipeline = $true{{/-first}}, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] - {{#isEnum}} - {{#allowableValues}} - [ValidateSet({{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}})] - {{/allowableValues}} - {{/isEnum}} - [{{{vendorExtensions.x-powershell-data-type}}}] - {{=<% %>=}} - ${<%paramName%>}, - <%={{ }}=%> - {{/allParams}} - {{#vendorExtensions.x-powershell-select-accept}} - [String] - [ValidateSet({{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}})] - $ReturnType, - {{/vendorExtensions.x-powershell-select-accept}} - [Switch] - $WithHttpInfo - ) - - Process { - 'Calling method: {{{vendorExtensions.x-powershell-method-name}}}' | Write-Debug - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $LocalVarAccepts = @() - $LocalVarContentTypes = @() - $LocalVarQueryParameters = @{} - $LocalVarHeaderParameters = @{} - $LocalVarFormParameters = @{} - $LocalVarPathParameters = @{} - $LocalVarCookieParameters = @{} - $LocalVarBodyParameter = $null - - $Configuration = Get-{{{apiNamePrefix}}}Configuration - {{#hasProduces}} - # HTTP header 'Accept' (if needed) - $LocalVarAccepts = @({{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}) - - {{/hasProduces}} - {{#vendorExtensions.x-powershell-select-accept}} - if ($ReturnType) { - # use the return type (MIME) provided by the user - $LocalVarAccepts = @($ReturnType) - } - - {{/vendorExtensions.x-powershell-select-accept}} - {{#hasConsumes}} - # HTTP header 'Content-Type' - $LocalVarContentTypes = @({{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}) - - {{/hasConsumes}} - $LocalVarUri = '{{{path}}}' - {{=< >=}} - <#pathParams> - if (!$) { - throw "Error! The required parameter `` missing when calling ." - } - $LocalVarUri = $LocalVarUri.replace('{}', $) - - <={{ }}=> - - {{#headerParams}} - {{#required}} - {{^isNullable}} - if (!${{{paramName}}}) { - throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." - } - $LocalVarHeaderParameters['{{baseName}}'] = ${{{paramName}}} - - {{/isNullable}} - {{/required}} - {{^required}} - {{^isNullable}} - if (${{{paramName}}}) { - $LocalVarHeaderParameters['{{baseName}}'] = ${{{paramName}}} - } - - {{/isNullable}} - {{#isNullable}} - $LocalVarHeaderParameters['{{baseName}}'] = ${{{paramName}}} - - {{/isNullable}} - {{/required}} - {{/headerParams}} - {{#queryParams}} - {{#required}} - {{^isNullable}} - if (!${{{paramName}}}) { - throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." - } - $LocalVarQueryParameters['{{baseName}}'] = ${{{paramName}}} - - {{/isNullable}} - {{/required}} - {{^required}} - {{^isNullable}} - if (${{{paramName}}}) { - $LocalVarQueryParameters['{{baseName}}'] = ${{{paramName}}} - } - - {{/isNullable}} - {{#isNullable}} - $LocalVarQueryParameters['{{baseName}}'] = ${{{paramName}}} - - {{/isNullable}} - {{/required}} - {{/queryParams}} - {{#formParams}} - {{#required}} - {{^isNullable}} - if (!${{{paramName}}}) { - throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." - } - $LocalVarFormParameters['{{baseName}}'] = ${{{paramName}}} - - {{/isNullable}} - {{/required}} - {{^required}} - {{^isNullable}} - if (${{{paramName}}}) { - $LocalVarFormParameters['{{baseName}}'] = ${{{paramName}}} - } - - {{/isNullable}} - {{#isNullable}} - $LocalVarFormParameters['{{baseName}}'] = ${{{paramName}}} - - {{/isNullable}} - {{/required}} - {{/formParams}} - {{#bodyParam}} - {{#required}} - {{^isNullable}} - if (!${{{paramName}}}) { - throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." - } - - {{/isNullable}} - {{/required}} - $LocalVarBodyParameter = ${{{paramName}}} | ConvertTo-Json - - {{/bodyParam}} - {{#authMethods}} - {{#isApiKey}} - {{#isKeyInHeader}} - if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) { - $LocalVarHeaderParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"] - Write-Verbose ("Using API key '{{{name}}}' in the header for authentication in {0}" -f $MyInvocation.MyCommand) - } - {{/isKeyInHeader}} - {{#isKeyInQuery}} - if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) { - $LocalVarQueryParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"] - Write-Verbose ("Using API key `{{{name}}}` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand) - } - {{/isKeyInQuery}} - {{#isKeyInCookie}} - if ($Configuration["Cookie"]) { - $LocalVarCookieParameters['{{{name}}}'] = $Configuration["Cookie"] - Write-Verbose ("Using API key `{{{name}}}` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand) - } - {{/isKeyInCookie}} - {{/isApiKey}} - {{#isBasicBasic}} - if ($Configuration["Username"] -and $Configuration["Password"]) { - $LocalVarBytes = [System.Text.Encoding]::UTF8.GetBytes($Configuration["Username"] + ":" + $Configuration["Password"]) - $LocalVarBase64Text =[Convert]::ToBase64String($LocalVarBytes) - $LocalVarHeaderParameters['Authorization'] = "Basic " + $LocalVarBase64Text - Write-Verbose ("Using HTTP basic authentication in {0}" -f $MyInvocation.MyCommand) - } - {{/isBasicBasic}} - {{#isBasicBearer}} - if ($Configuration["AccessToken"]) { - $LocalVarHeaderParameters['Authorization'] = "Bearer " + $Configuration["AccessToken"] - Write-Verbose ("Using Bearer authentication in {0}" -f $MyInvocation.MyCommand) - } - {{/isBasicBearer}} - - {{/authMethods}} - $LocalVarResult = Invoke-{{{apiNamePrefix}}}ApiClient -Method '{{httpMethod}}' ` - -Uri $LocalVarUri ` - -Accepts $LocalVarAccepts ` - -ContentTypes $LocalVarContentTypes ` - -Body $LocalVarBodyParameter ` - -HeaderParameters $LocalVarHeaderParameters ` - -QueryParameters $LocalVarQueryParameters ` - -FormParameters $LocalVarFormParameters ` - -CookieParameters $LocalVarCookieParameters ` - -ReturnType "{{#returnType}}{{{.}}}{{/returnType}}" - - if ($WithHttpInfo.IsPresent) { - return $LocalVarResult - } else { - return $LocalVarResult["Response"] - } - } -} - -{{/operation}} -{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/api_doc.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/api_doc.mustache deleted file mode 100644 index 97e5de1b693..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/api_doc.mustache +++ /dev/null @@ -1,87 +0,0 @@ -# {{packageName}}.{{apiPackage}}.{{classname}}{{#description}} -{{description}}{{/description}} - -All URIs are relative to *{{{basePath}}}* - -Method | HTTP request | Description -------------- | ------------- | ------------- -{{#operations}}{{#operation}}[**{{vendorExtensions.x-powershell-method-name}}**]({{classname}}.md#{{vendorExtensions.x-powershell-method-name-lowercase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} -{{/operation}}{{/operations}} - -{{#operations}} -{{#operation}} - -# **{{{vendorExtensions.x-powershell-method-name}}}** -> {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{{vendorExtensions.x-powershell-method-name}}}
    -{{#allParams}} ->         [-{{paramName}}] <{{{vendorExtensions.x-powershell-data-type}}}>
    -{{/allParams}} - -{{{summary}}}{{#notes}} - -{{{notes}}}{{/notes}} - -### Example -```powershell -Import-Module -Name {{{packageName}}} - -{{#hasAuthMethods}} -$Configuration = Get-{{{packageName}}}Configuration -{{#authMethods}} -{{#isBasic}} -# Configure HTTP basic authorization: {{{name}}} -$Configuration["Username"] = "YOUR_USERNAME"; -$Configuration["Password"] = "YOUR_PASSWORD"; -{{/isBasic}} -{{#isApiKey}} -# Configure API key authorization: {{{name}}} -$Configuration["ApiKey"]["{{{keyParamName}}}"] = "YOUR_API_KEY" -# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed -#$Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"] = "Bearer" -{{/isApiKey}} -{{#isOAuth}} -# Configure OAuth2 access token for authorization: {{{name}}} -$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN"; -{{/isOAuth}} -{{/authMethods}} - -{{/hasAuthMethods}} -{{#allParams}} -${{paramName}} = {{{vendorExtensions.x-powershell-example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} -{{/allParams}} - -{{#summary}} -# {{{.}}} -{{/summary}} -try { - {{#returnType}}{{returnType}} $Result = {{/returnType}}{{{vendorExtensions.x-powershell-method-name}}}{{#allParams}} -{{paramName}} ${{paramName}}{{/allParams}} -} catch { - Write-Host ("Exception occured when calling {{{vendorExtensions.x-powershell-method-name}}}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json)) - Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) -} -``` - -### Parameters -{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} -Name | Type | Description | Notes -------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}} -{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{#isContainer}}{{baseType}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} -{{/allParams}} - -### Return type - -{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}} - -### Authorization - -{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](../README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}} - -### HTTP request headers - - - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} - - **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - -{{/operation}} -{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/api_test.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/api_test.mustache deleted file mode 100644 index e43e849eb4a..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/api_test.mustache +++ /dev/null @@ -1,15 +0,0 @@ -{{> partial_header}} -Describe -tag '{{{packageName}}}' -name '{{{classname}}}' { -{{#operations}} -{{#operation}} - Context '{{{vendorExtensions.x-powershell-method-name}}}' { - It 'Test {{{vendorExtensions.x-powershell-method-name}}}' { - #$TestResult = Invoke-PetApiGetPetById{{#allParams}} -{{{paramName}}} "TEST_VALUE"{{/allParams}} - #$TestResult | Should BeOfType TODO - #$TestResult.property | Should Be 0 - } - } - -{{/operation}} -{{/operations}} -} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache deleted file mode 100644 index 81d5dba1324..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache +++ /dev/null @@ -1,107 +0,0 @@ -{{> partial_header}} -{{#models}} -{{#model}} -<# -.SYNOPSIS - -{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}} - -.DESCRIPTION - -{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} - -{{#allVars}} -.PARAMETER {{{name}}} -{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} - -{{/allVars}} -.OUTPUTS - -{{{classname}}} -#> - -function Initialize-{{{apiNamePrefix}}}{{{classname}}} { - [CmdletBinding()] - Param ( -{{#allVars}} - [Parameter(Position = {{vendorExtensions.x-index}}, ValueFromPipelineByPropertyName = $true)] - {{#pattern}} - [ValidatePattern("{{{.}}}")] - {{/pattern}} - {{#isEnum}} - {{#allowableValues}} - [ValidateSet({{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}})] - {{/allowableValues}} - {{/isEnum}} - [{{vendorExtensions.x-powershell-data-type}}] - {{=<% %>=}} - ${<%name%>}<%^-last%>,<%/-last%> - <%={{ }}=%> -{{/allVars}} - ) - - Process { - 'Creating PSCustomObject: {{{packageName}}} => {{{apiNamePrefix}}}{{{classname}}}' | Write-Debug - $PSBoundParameters | Out-DebugParameter | Write-Debug - - {{#vars}} - {{^isNullable}} - {{#required}} - if (!${{{name}}}) { - throw "invalid value for '{{{name}}}', '{{{name}}}' cannot be null." - } - - {{/required}} - {{/isNullable}} - {{#hasValidation}} - {{#maxLength}} - if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -gt {{{maxLength}}}) { - throw "invalid value for '{{{name}}}', the character length must be smaller than or equal to {{{maxLength}}}." - } - - {{/maxLength}} - {{#minLength}} - if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -lt {{{minLength}}}) { - throw "invalid value for '{{{name}}}', the character length must be great than or equal to {{{minLength}}}." - } - - {{/minLength}} - {{#maximum}} - if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}} {{#exclusiveMaximum}}-ge{{/exclusiveMaximum}}{{^exclusiveMaximum}}-gt{{/exclusiveMaximum}} {{{maximum}}}) { - throw "invalid value for '{{{name}}}', must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}." - } - - {{/maximum}} - {{#minimum}} - if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}} {{#exclusiveMinimum}}-le{{/exclusiveMinimum}}{{^exclusiveMinimum}}-lt{{/exclusiveMinimum}} {{{minimum}}}) { - throw "invalid value for '{{{name}}}', must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}." - } - - {{/minimum}} - {{#maxItems}} - if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -gt {{{maxItems}}}) { - throw "invalid value for '{{{name}}}', number of items must be less than or equal to {{{maxItems}}}." - } - - {{/maxItems}} - {{#minItems}} - if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -lt {{{minItems}}}) { - throw "invalid value for '{{{name}}}', number of items must be greater than or equal to {{{minItems}}}." - } - - {{/minItems}} - {{/hasValidation}} - {{/vars}} - $PSO = [PSCustomObject]@{ - {{=<< >>=}} - <<#allVars>> - "<>" = ${<>} - <> - <<={{ }}=>> - } - - return $PSO - } -} -{{/model}} -{{/models}} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/model_doc.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/model_doc.mustache deleted file mode 100644 index 253050a9457..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/model_doc.mustache +++ /dev/null @@ -1,29 +0,0 @@ -{{#models}} -{{#model}} -# {{{classname}}} -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}} -{{/vars}} - -## Examples - -- Prepare the resource -```powershell -Initialize-{{{packageName}}}{{{classname}}} {{#vars}} -{{name}} {{example}}{{#hasMore}} ` - {{/hasMore}} -{{/vars}} - -``` - -- Convert the resource to JSON -```powershell -${{className}} | Convert-ToJSON -``` - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - -{{/model}} -{{/models}} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/model_test.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/model_test.mustache deleted file mode 100644 index 626b0034712..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/model_test.mustache +++ /dev/null @@ -1,15 +0,0 @@ -{{> partial_header}} -{{#models}} -{{#model}} -Describe -tag '{{{packageName}}}' -name '{{{classname}}}' { - Context '{{{classname}}}' { - It 'New-{{{classname}}}' { - # a simple test to create an object - #$NewObject = New-{{{classname}}}{{#vars}} -{{name}} "TEST_VALUE"{{/vars}} - #$NewObject | Should BeOfType {{classname}} - #$NewObject.property | Should Be 0 - } - } -} -{{/model}} -{{/models}} 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 f7da412a28f..ed875bc5e82 100644 --- a/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache @@ -1,3 +1,4 @@ +{{> partial_header}} function Get-FunctionsToExport { [CmdletBinding()] Param ( @@ -38,17 +39,7 @@ function Get-FunctionsToExport { } $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path -$ClientPath = ("{{{csharpClientPath}}}" | Resolve-Path).ProviderPath -$FunctionPath = 'API', 'Model' | ForEach-Object {Join-Path "$ScriptDir\src\{{{packageName}}}\" $_} -$BinPath = "$ScriptDir\src\{{{packageName}}}\Bin" - -Start-Process -FilePath "$ClientPath\build.bat" -WorkingDirectory $ClientPath -Wait -NoNewWindow - -if (!(Test-Path "$ScriptDir\src\{{{packageName}}}\Bin" -PathType Container)) { - New-Item "$ScriptDir\src\{{{packageName}}}\Bin" -ItemType Directory > $null -} - -Copy-Item "$ClientPath\bin\*.dll" $BinPath +$FunctionPath = 'Api', 'Model', 'Client' | ForEach-Object {Join-Path "$ScriptDir\src\{{{packageName}}}\" $_} $Manifest = @{ Path = "$ScriptDir\src\{{{packageName}}}\{{{packageName}}}.psd1" @@ -57,40 +48,19 @@ $Manifest = @{ CompanyName = 'openapitools.org' Description = '{{{packageName}}} - the PowerShell module for {{{appName}}}' + ModuleVersion = '{{{packageVersion}}}' + RootModule = '{{{packageName}}}.psm1' Guid = '{{packageGuid}}' # Has to be static, otherwise each new build will be considered different module PowerShellVersion = '3.0' - RequiredAssemblies = Get-ChildItem "$BinPath\*.dll" | ForEach-Object { - Join-Path $_.Directory.Name $_.Name - } - FunctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-FunctionsToExport VariablesToExport = @() AliasesToExport = @() CmdletsToExport = @() - # Should we use prefix to prevent command name collisions? - # https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/ - # - # Kirk Munro recommends against it: - # https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/#comment-20820 - # - # If not, we'd need to generate functions name with prefix. For examples, - # -{{#apiInfo}} -{{#apis}} -{{#operations}} -{{#operation}} -{{#-first}} - # DefaultCommandPrefix = '{{{classname}}}' -{{/-first}} -{{/operation}} -{{/operations}} -{{/apis}} -{{/apiInfo}} } New-ModuleManifest @Manifest diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/Get-CommonParameters.mustache b/modules/openapi-generator/src/main/resources/powershell/Get-CommonParameters.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/Get-CommonParameters.mustache rename to modules/openapi-generator/src/main/resources/powershell/Get-CommonParameters.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell/Get-CommonParameters.ps1 b/modules/openapi-generator/src/main/resources/powershell/Get-CommonParameters.ps1 deleted file mode 100644 index 31a0a1ff3af..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell/Get-CommonParameters.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -<# -.Synopsis - Helper function to get common parameters (Verbose, Debug, etc.) -.Example - Get-CommonParameters -#> -function Get-CommonParameters { - function tmp { - [CmdletBinding()] - Param () - } - - (Get-Command -Name tmp -CommandType Function).Parameters.Keys -} 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 6d0339a2b4e..ce575233bb8 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 @@ -1,33 +1,23 @@ +{{>partial_header}} #region Import functions -'API', 'Model', 'Private' | Get-ChildItem -Path { +# set $ErrorActionPreference to 'Stop' globally +$ErrorActionPreference = 'Stop' + +# store the API client's configuration +$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 { Join-Path $PSScriptRoot $_ } -Filter '*.ps1' | ForEach-Object { - Write-Verbose "Importing file: $($_.BaseName)" + Write-Debug "Importing file: $($_.BaseName)" try { . $_.FullName } catch { - Write-Verbose "Can't import function!" + Write-Error -Message "Failed to import function $($_.Fullname): $_" } } #endregion - - -#region Initialize APIs - -{{#apiInfo}} -{{#apis}} -{{#operations}} -{{#operation}} -{{#-first}} -'Creating object: {{{packageName}}}.Api.{{{classname}}}' | Write-Verbose -$Script:{{{classname}}}= New-Object -TypeName {{{packageName}}}.Api.{{{classname}}} -ArgumentList @($null) - -{{/-first}} -{{/operation}} -{{/operations}} -{{/apis}} -{{/apiInfo}} - -#endregion diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/Out-DebugParameter.mustache b/modules/openapi-generator/src/main/resources/powershell/Out-DebugParameter.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/Out-DebugParameter.mustache rename to modules/openapi-generator/src/main/resources/powershell/Out-DebugParameter.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell/Out-DebugParameter.ps1 b/modules/openapi-generator/src/main/resources/powershell/Out-DebugParameter.ps1 deleted file mode 100644 index ca18c391cc1..00000000000 --- a/modules/openapi-generator/src/main/resources/powershell/Out-DebugParameter.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -<# -.Synopsis - Helper function to format debug parameter output. -.Example - $PSBoundParameters | Out-DebugParameter | Write-Debug -#> -function Out-DebugParameter { - [CmdletBinding()] - Param ( - [Parameter(ValueFromPipeline = $true, Mandatory = $true)] - [AllowEmptyCollection()] - $InputObject - ) - - Begin { - $CommonParameters = Get-CommonParameters - } - - Process { - $InputObject.GetEnumerator() | Where-Object { - $CommonParameters -notcontains $_.Key - } | Format-Table -AutoSize -Property ( - @{ - Name = 'Parameter' - Expression = {$_.Key} - }, - @{ - Name = 'Value' - Expression = {$_.Value} - } - ) | Out-String -Stream | ForEach-Object { - if ($_.Trim()) { - $_ - } - } - } -} diff --git a/modules/openapi-generator/src/main/resources/powershell/README.mustache b/modules/openapi-generator/src/main/resources/powershell/README.mustache index fae062b7d2b..357274b6543 100644 --- a/modules/openapi-generator/src/main/resources/powershell/README.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/README.mustache @@ -2,8 +2,8 @@ {{#appDescriptionWithNewLines}} {{{appDescriptionWithNewLines}}} -{{/appDescriptionWithNewLines}} +{{/appDescriptionWithNewLines}} This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: {{appVersion}} @@ -18,21 +18,97 @@ This PowerShell module is automatically generated by the [OpenAPI Generator](htt ## Frameworks supported -- PowerShell 3.0 or later +- PowerShell 5.0 or later ## Dependencies -- C# API client generated by OpenAPI Generator AND should be located in {{{csharpClientPath}}} as stated in Build.ps1 ## Installation -Run the following command to generate the DLL -- [Windows] `Build.ps1` -Then import module from the .\src\{{{packageName}}} folder: +{{#powershellGalleryUrl}} +To install from PowerShell Gallery ({{{powershellGalleryUrl}}}) ```powershell -using {{packageName}}.{{apiPackage}}; -using {{packageName}}.Client; -using {{packageName}}.{{modelPackage}}; +Import-Module -Name {{{powershellGalleryId}}} -Verbose +``` +{{/powershellGalleryUrl}} + +To install from the source, run the following command to build and install the PowerShell module locally: +```powershell +Build.ps1 +Import-Module -Name '.\src\{{{packageName}}}' -Verbose ``` +To avoid function name collision, one can use `-Prefix`, e.g. `Import-Module -Name '.\src\{{{packageName}}}' -Prefix prefix` + +To uninstall the module, simply run: +```powershell +Remove-Module -FullyQualifiedName @{ModuleName = "{{{packageName}}}"; ModuleVersion = "{{{packageVersion}}}"} +``` + + +## Tests + +To install and run `Pester`, please execute the following commands in the terminal: + +```powershell +Install-module -name Pester -force + +Invoker-Pester +``` + +For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debugging and disable it with `$DebugPreference = 'SilentlyContinue'` when done with the troubleshooting. + +## Documentation for API Endpoints + +All URIs are relative to *{{{basePath}}}* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{vendorExtensions.x-powershell-method-name}}**]({{apiDocPath}}{{classname}}.md#{{vendorExtensions.x-powershell-method-name-lowercase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}} +{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} + +## Documentation for Models + +{{#modelPackage}} +{{#models}}{{#model}} - [{{{modelPackage}}}.{{{classname}}}]({{modelDocPath}}{{{classname}}}.md) +{{/model}}{{/models}} +{{/modelPackage}} +{{^modelPackage}} +No model defined in this package +{{/modelPackage}} + +## Documentation for Authorization + +{{^authMethods}} +All endpoints do not require authorization. +{{/authMethods}} +{{#authMethods}} +{{#last}} +Authentication schemes defined for the API: +{{/last}} +{{/authMethods}} +{{#authMethods}} + +### {{name}} + +{{#isApiKey}}- **Type**: API key + +- **API key parameter name**: {{keyParamName}} +- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} +{{/isApiKey}} +{{#isBasic}} + +- **Type**: HTTP basic authentication +{{/isBasic}} +{{#isOAuth}} + +- **Type**: OAuth +- **Flow**: {{flow}} +- **Authorization URL**: {{authorizationUrl}} +- **Scopes**: {{^scopes}}N/A{{/scopes}} +{{#scopes}} - {{scope}}: {{description}} +{{/scopes}} +{{/isOAuth}} + +{{/authMethods}} diff --git a/modules/openapi-generator/src/main/resources/powershell/api.mustache b/modules/openapi-generator/src/main/resources/powershell/api.mustache index 98fb6bb7d16..e89e0bd91cc 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api.mustache @@ -1,28 +1,233 @@ +{{> partial_header}} {{#operations}} {{#operation}} -function Invoke-{{{classname}}}{{{operationId}}} { +<# +.SYNOPSIS + +{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}} + +.DESCRIPTION + +{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} + +{{#allParams}} +.PARAMETER {{{paramName}}} +{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} + +{{/allParams}} +{{#vendorExtensions.x-powershell-select-accept}} +.PARAMETER ReturnType + +Select the return type (optional): {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}} + +{{/vendorExtensions.x-powershell-select-accept}} +.PARAMETER WithHttpInfo + +A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response + +.OUTPUTS + +{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}None{{/returnType}} +#> +function {{{vendorExtensions.x-powershell-method-name}}} { [CmdletBinding()] Param ( {{#allParams}} - [Parameter(Position = {{vendorExtensions.x-index}}, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = {{#required}}$true{{/required}}{{^required}}$false{{/required}})] - [{{^isContainer}}{{^isPrimitiveType}}{{^isFile}}{{{packageName}}}.Model.{{/isFile}}{{/isPrimitiveType}}{{/isContainer}}{{{dataType}}}] + [Parameter(Position = {{vendorExtensions.x-index}}{{#-first}}, ValueFromPipeline = $true{{/-first}}, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] + {{#isEnum}} + {{#allowableValues}} + [ValidateSet({{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}})] + {{/allowableValues}} + {{/isEnum}} + [{{{vendorExtensions.x-powershell-data-type}}}] {{=<% %>=}} - ${<%paramName%>}<%^-last%>,<%/-last%> + ${<%paramName%>}, <%={{ }}=%> {{/allParams}} + {{#vendorExtensions.x-powershell-select-accept}} + [String] + [ValidateSet({{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}})] + $ReturnType, + {{/vendorExtensions.x-powershell-select-accept}} + [Switch] + $WithHttpInfo ) Process { - 'Calling method: {{{classname}}}-{{{operationId}}}' | Write-Verbose + 'Calling method: {{{vendorExtensions.x-powershell-method-name}}}' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug - $Script:{{{classname}}}.{{{operationId}}}( - {{#allParams}} - {{=<% %>=}} - ${<%paramName%>}<%^-last%>,<%/-last%> - <%={{ }}=%> - {{/allParams}} - ) + $LocalVarAccepts = @() + $LocalVarContentTypes = @() + $LocalVarQueryParameters = @{} + $LocalVarHeaderParameters = @{} + $LocalVarFormParameters = @{} + $LocalVarPathParameters = @{} + $LocalVarCookieParameters = @{} + $LocalVarBodyParameter = $null + + $Configuration = Get-{{{apiNamePrefix}}}Configuration + {{#hasProduces}} + # HTTP header 'Accept' (if needed) + $LocalVarAccepts = @({{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}) + + {{/hasProduces}} + {{#vendorExtensions.x-powershell-select-accept}} + if ($ReturnType) { + # use the return type (MIME) provided by the user + $LocalVarAccepts = @($ReturnType) + } + + {{/vendorExtensions.x-powershell-select-accept}} + {{#hasConsumes}} + # HTTP header 'Content-Type' + $LocalVarContentTypes = @({{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}) + + {{/hasConsumes}} + $LocalVarUri = '{{{path}}}' + {{=< >=}} + <#pathParams> + if (!$) { + throw "Error! The required parameter `` missing when calling ." + } + $LocalVarUri = $LocalVarUri.replace('{}', $) + + <={{ }}=> + + {{#headerParams}} + {{#required}} + {{^isNullable}} + if (!${{{paramName}}}) { + throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." + } + $LocalVarHeaderParameters['{{baseName}}'] = ${{{paramName}}} + + {{/isNullable}} + {{/required}} + {{^required}} + {{^isNullable}} + if (${{{paramName}}}) { + $LocalVarHeaderParameters['{{baseName}}'] = ${{{paramName}}} + } + + {{/isNullable}} + {{#isNullable}} + $LocalVarHeaderParameters['{{baseName}}'] = ${{{paramName}}} + + {{/isNullable}} + {{/required}} + {{/headerParams}} + {{#queryParams}} + {{#required}} + {{^isNullable}} + if (!${{{paramName}}}) { + throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." + } + $LocalVarQueryParameters['{{baseName}}'] = ${{{paramName}}} + + {{/isNullable}} + {{/required}} + {{^required}} + {{^isNullable}} + if (${{{paramName}}}) { + $LocalVarQueryParameters['{{baseName}}'] = ${{{paramName}}} + } + + {{/isNullable}} + {{#isNullable}} + $LocalVarQueryParameters['{{baseName}}'] = ${{{paramName}}} + + {{/isNullable}} + {{/required}} + {{/queryParams}} + {{#formParams}} + {{#required}} + {{^isNullable}} + if (!${{{paramName}}}) { + throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." + } + $LocalVarFormParameters['{{baseName}}'] = ${{{paramName}}} + + {{/isNullable}} + {{/required}} + {{^required}} + {{^isNullable}} + if (${{{paramName}}}) { + $LocalVarFormParameters['{{baseName}}'] = ${{{paramName}}} + } + + {{/isNullable}} + {{#isNullable}} + $LocalVarFormParameters['{{baseName}}'] = ${{{paramName}}} + + {{/isNullable}} + {{/required}} + {{/formParams}} + {{#bodyParam}} + {{#required}} + {{^isNullable}} + if (!${{{paramName}}}) { + throw "Error! The required parameter `{{paramName}}` missing when calling {{operationId}}." + } + + {{/isNullable}} + {{/required}} + $LocalVarBodyParameter = ${{{paramName}}} | ConvertTo-Json + + {{/bodyParam}} + {{#authMethods}} + {{#isApiKey}} + {{#isKeyInHeader}} + if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) { + $LocalVarHeaderParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"] + Write-Verbose ("Using API key '{{{name}}}' in the header for authentication in {0}" -f $MyInvocation.MyCommand) + } + {{/isKeyInHeader}} + {{#isKeyInQuery}} + if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) { + $LocalVarQueryParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"] + Write-Verbose ("Using API key `{{{name}}}` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand) + } + {{/isKeyInQuery}} + {{#isKeyInCookie}} + if ($Configuration["Cookie"]) { + $LocalVarCookieParameters['{{{name}}}'] = $Configuration["Cookie"] + Write-Verbose ("Using API key `{{{name}}}` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand) + } + {{/isKeyInCookie}} + {{/isApiKey}} + {{#isBasicBasic}} + if ($Configuration["Username"] -and $Configuration["Password"]) { + $LocalVarBytes = [System.Text.Encoding]::UTF8.GetBytes($Configuration["Username"] + ":" + $Configuration["Password"]) + $LocalVarBase64Text =[Convert]::ToBase64String($LocalVarBytes) + $LocalVarHeaderParameters['Authorization'] = "Basic " + $LocalVarBase64Text + Write-Verbose ("Using HTTP basic authentication in {0}" -f $MyInvocation.MyCommand) + } + {{/isBasicBasic}} + {{#isBasicBearer}} + if ($Configuration["AccessToken"]) { + $LocalVarHeaderParameters['Authorization'] = "Bearer " + $Configuration["AccessToken"] + Write-Verbose ("Using Bearer authentication in {0}" -f $MyInvocation.MyCommand) + } + {{/isBasicBearer}} + + {{/authMethods}} + $LocalVarResult = Invoke-{{{apiNamePrefix}}}ApiClient -Method '{{httpMethod}}' ` + -Uri $LocalVarUri ` + -Accepts $LocalVarAccepts ` + -ContentTypes $LocalVarContentTypes ` + -Body $LocalVarBodyParameter ` + -HeaderParameters $LocalVarHeaderParameters ` + -QueryParameters $LocalVarQueryParameters ` + -FormParameters $LocalVarFormParameters ` + -CookieParameters $LocalVarCookieParameters ` + -ReturnType "{{#returnType}}{{{.}}}{{/returnType}}" + + if ($WithHttpInfo.IsPresent) { + return $LocalVarResult + } else { + return $LocalVarResult["Response"] + } } } diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/api_client.mustache b/modules/openapi-generator/src/main/resources/powershell/api_client.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/api_client.mustache rename to modules/openapi-generator/src/main/resources/powershell/api_client.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell/api_doc.mustache b/modules/openapi-generator/src/main/resources/powershell/api_doc.mustache index ff3cf4fc60a..97e5de1b693 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api_doc.mustache @@ -5,77 +5,59 @@ All URIs are relative to *{{{basePath}}}* Method | HTTP request | Description ------------- | ------------- | ------------- -{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} +{{#operations}}{{#operation}}[**{{vendorExtensions.x-powershell-method-name}}**]({{classname}}.md#{{vendorExtensions.x-powershell-method-name-lowercase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} {{/operation}}{{/operations}} {{#operations}} {{#operation}} - -# **{{{operationId}}}** -> {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}} ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + +# **{{{vendorExtensions.x-powershell-method-name}}}** +> {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{{vendorExtensions.x-powershell-method-name}}}
    +{{#allParams}} +>         [-{{paramName}}] <{{{vendorExtensions.x-powershell-data-type}}}>
    +{{/allParams}} {{{summary}}}{{#notes}} {{{notes}}}{{/notes}} ### Example -```csharp -using System; -using System.Diagnostics; -using {{packageName}}.{{apiPackage}}; -using {{packageName}}.Client; -using {{packageName}}.{{modelPackage}}; +```powershell +Import-Module -Name {{{packageName}}} -namespace Example -{ - public class {{operationId}}Example - { - public void main() - { - {{#hasAuthMethods}} - {{#authMethods}} - {{#isBasic}} - // Configure HTTP basic authorization: {{{name}}} - Configuration.Default.Username = "YOUR_USERNAME"; - Configuration.Default.Password = "YOUR_PASSWORD"; - {{/isBasic}} - {{#isApiKey}} - // Configure API key authorization: {{{name}}} - Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY"); - // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed - // Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer"); - {{/isApiKey}} - {{#isOAuth}} - // Configure OAuth2 access token for authorization: {{{name}}} - Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; - {{/isOAuth}} - {{/authMethods}} +{{#hasAuthMethods}} +$Configuration = Get-{{{packageName}}}Configuration +{{#authMethods}} +{{#isBasic}} +# Configure HTTP basic authorization: {{{name}}} +$Configuration["Username"] = "YOUR_USERNAME"; +$Configuration["Password"] = "YOUR_PASSWORD"; +{{/isBasic}} +{{#isApiKey}} +# Configure API key authorization: {{{name}}} +$Configuration["ApiKey"]["{{{keyParamName}}}"] = "YOUR_API_KEY" +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +#$Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"] = "Bearer" +{{/isApiKey}} +{{#isOAuth}} +# Configure OAuth2 access token for authorization: {{{name}}} +$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN"; +{{/isOAuth}} +{{/authMethods}} - {{/hasAuthMethods}} - var apiInstance = new {{classname}}(); - {{#allParams}} - {{#isPrimitiveType}} - var {{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} - {{/isPrimitiveType}} - {{^isPrimitiveType}} - var {{paramName}} = new {{{dataType}}}(); // {{{dataType}}} | {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} - {{/isPrimitiveType}} - {{/allParams}} +{{/hasAuthMethods}} +{{#allParams}} +${{paramName}} = {{{vendorExtensions.x-powershell-example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} +{{/allParams}} - try - { - {{#summary}} - // {{{.}}} - {{/summary}} - {{#returnType}}{{returnType}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} - Debug.WriteLine(result);{{/returnType}} - } - catch (Exception e) - { - Debug.Print("Exception when calling {{classname}}.{{operationId}}: " + e.Message ); - } - } - } +{{#summary}} +# {{{.}}} +{{/summary}} +try { + {{#returnType}}{{returnType}} $Result = {{/returnType}}{{{vendorExtensions.x-powershell-method-name}}}{{#allParams}} -{{paramName}} ${{paramName}}{{/allParams}} +} catch { + Write-Host ("Exception occured when calling {{{vendorExtensions.x-powershell-method-name}}}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json)) + Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) } ``` diff --git a/modules/openapi-generator/src/main/resources/powershell/api_test.mustache b/modules/openapi-generator/src/main/resources/powershell/api_test.mustache index faa54d5e17f..e43e849eb4a 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api_test.mustache @@ -1,14 +1,12 @@ -# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech) -# Please replace "TEST_VALUE" with a proper value and uncomment the code for testing the function - -Describe '{{{packageName}}} {{{classname}}}' { +{{> partial_header}} +Describe -tag '{{{packageName}}}' -name '{{{classname}}}' { {{#operations}} {{#operation}} - Context '{{{classname}}}' { - It 'Invoke-{{{classname}}}{{{operationId}}}' { - $ret = Invoke-PetApiGetPetById{{#allParams}} -{{{paramName}}} "TEST_VALUE"{{/allParams}} - #$ret | Should BeOfType {{{packageName}}}.Model.ModelNameHere - #$ret.property | Should Be 0 + Context '{{{vendorExtensions.x-powershell-method-name}}}' { + It 'Test {{{vendorExtensions.x-powershell-method-name}}}' { + #$TestResult = Invoke-PetApiGetPetById{{#allParams}} -{{{paramName}}} "TEST_VALUE"{{/allParams}} + #$TestResult | Should BeOfType TODO + #$TestResult.property | Should Be 0 } } diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/appveyor.mustache b/modules/openapi-generator/src/main/resources/powershell/appveyor.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/appveyor.mustache rename to modules/openapi-generator/src/main/resources/powershell/appveyor.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache b/modules/openapi-generator/src/main/resources/powershell/configuration.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache rename to modules/openapi-generator/src/main/resources/powershell/configuration.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/http_signature_auth.mustache b/modules/openapi-generator/src/main/resources/powershell/http_signature_auth.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/http_signature_auth.mustache rename to modules/openapi-generator/src/main/resources/powershell/http_signature_auth.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell/model.mustache b/modules/openapi-generator/src/main/resources/powershell/model.mustache index c03f5daca65..81d5dba1324 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model.mustache @@ -1,28 +1,106 @@ +{{> partial_header}} {{#models}} {{#model}} -function New-{{{classname}}} { +<# +.SYNOPSIS + +{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}} + +.DESCRIPTION + +{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} + +{{#allVars}} +.PARAMETER {{{name}}} +{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}} + +{{/allVars}} +.OUTPUTS + +{{{classname}}} +#> + +function Initialize-{{{apiNamePrefix}}}{{{classname}}} { [CmdletBinding()] Param ( -{{#vars}} - [Parameter(Position = {{vendorExtensions.x-index}}, ValueFromPipelineByPropertyName = $true{{#required}}, Mandatory = $true{{/required}})] - [{{#isString}}{{{dataType}}}{{/isString}}{{^isString}}{{#isListContainer}}{{{dataType}}}{{/isListContainer}}{{^isListContainer}}{{#isPrimitiveType}}{{^required}}System.Nullable[{{/required}}{{dataType}}{{^required}}]{{/required}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{dataType}}{{/isPrimitiveType}}{{/isListContainer}}{{/isString}}] +{{#allVars}} + [Parameter(Position = {{vendorExtensions.x-index}}, ValueFromPipelineByPropertyName = $true)] + {{#pattern}} + [ValidatePattern("{{{.}}}")] + {{/pattern}} + {{#isEnum}} + {{#allowableValues}} + [ValidateSet({{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}})] + {{/allowableValues}} + {{/isEnum}} + [{{vendorExtensions.x-powershell-data-type}}] {{=<% %>=}} ${<%name%>}<%^-last%>,<%/-last%> <%={{ }}=%> -{{/vars}} +{{/allVars}} ) Process { - 'Creating object: {{{packageName}}}.Model.{{{classname}}}' | Write-Verbose + 'Creating PSCustomObject: {{{packageName}}} => {{{apiNamePrefix}}}{{{classname}}}' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug - New-Object -TypeName {{{packageName}}}.Model.{{{classname}}} -ArgumentList @( -{{#vars}} - {{=<% %>=}} - ${<%name%>}<%^-last%>,<%/-last%> - <%={{ }}=%> -{{/vars}} - ) + {{#vars}} + {{^isNullable}} + {{#required}} + if (!${{{name}}}) { + throw "invalid value for '{{{name}}}', '{{{name}}}' cannot be null." + } + + {{/required}} + {{/isNullable}} + {{#hasValidation}} + {{#maxLength}} + if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -gt {{{maxLength}}}) { + throw "invalid value for '{{{name}}}', the character length must be smaller than or equal to {{{maxLength}}}." + } + + {{/maxLength}} + {{#minLength}} + if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -lt {{{minLength}}}) { + throw "invalid value for '{{{name}}}', the character length must be great than or equal to {{{minLength}}}." + } + + {{/minLength}} + {{#maximum}} + if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}} {{#exclusiveMaximum}}-ge{{/exclusiveMaximum}}{{^exclusiveMaximum}}-gt{{/exclusiveMaximum}} {{{maximum}}}) { + throw "invalid value for '{{{name}}}', must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}." + } + + {{/maximum}} + {{#minimum}} + if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}} {{#exclusiveMinimum}}-le{{/exclusiveMinimum}}{{^exclusiveMinimum}}-lt{{/exclusiveMinimum}} {{{minimum}}}) { + throw "invalid value for '{{{name}}}', must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}." + } + + {{/minimum}} + {{#maxItems}} + if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -gt {{{maxItems}}}) { + throw "invalid value for '{{{name}}}', number of items must be less than or equal to {{{maxItems}}}." + } + + {{/maxItems}} + {{#minItems}} + if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -lt {{{minItems}}}) { + throw "invalid value for '{{{name}}}', number of items must be greater than or equal to {{{minItems}}}." + } + + {{/minItems}} + {{/hasValidation}} + {{/vars}} + $PSO = [PSCustomObject]@{ + {{=<< >>=}} + <<#allVars>> + "<>" = ${<>} + <> + <<={{ }}=>> + } + + return $PSO } } {{/model}} diff --git a/modules/openapi-generator/src/main/resources/powershell/model_doc.mustache b/modules/openapi-generator/src/main/resources/powershell/model_doc.mustache index 04d7df156f9..253050a9457 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_doc.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_doc.mustache @@ -1,6 +1,6 @@ {{#models}} {{#model}} -# {{{packageName}}}.{{modelPackage}}.{{{classname}}} +# {{{classname}}} ## Properties Name | Type | Description | Notes @@ -8,6 +8,21 @@ Name | Type | Description | Notes {{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}} {{/vars}} +## Examples + +- Prepare the resource +```powershell +Initialize-{{{packageName}}}{{{classname}}} {{#vars}} -{{name}} {{example}}{{#hasMore}} ` + {{/hasMore}} +{{/vars}} + +``` + +- Convert the resource to JSON +```powershell +${{className}} | Convert-ToJSON +``` + [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) {{/model}} diff --git a/modules/openapi-generator/src/main/resources/powershell/model_test.mustache b/modules/openapi-generator/src/main/resources/powershell/model_test.mustache index e61c02beb47..626b0034712 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_test.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_test.mustache @@ -1,6 +1,15 @@ +{{> partial_header}} {{#models}} {{#model}} -## TODO we need to update the template to test the model files - +Describe -tag '{{{packageName}}}' -name '{{{classname}}}' { + Context '{{{classname}}}' { + It 'New-{{{classname}}}' { + # a simple test to create an object + #$NewObject = New-{{{classname}}}{{#vars}} -{{name}} "TEST_VALUE"{{/vars}} + #$NewObject | Should BeOfType {{classname}} + #$NewObject.property | Should Be 0 + } + } +} {{/model}} {{/models}} diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/partial_header.mustache b/modules/openapi-generator/src/main/resources/powershell/partial_header.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/partial_header.mustache rename to modules/openapi-generator/src/main/resources/powershell/partial_header.mustache diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/rsa_provider.mustache b/modules/openapi-generator/src/main/resources/powershell/rsa_provider.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/powershell-experimental/rsa_provider.mustache rename to modules/openapi-generator/src/main/resources/powershell/rsa_provider.mustache diff --git a/samples/client/petstore/powershell-experimental/.openapi-generator-ignore b/samples/client/petstore/powershell-experimental/.openapi-generator-ignore deleted file mode 100644 index 7484ee590a3..00000000000 --- a/samples/client/petstore/powershell-experimental/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator - -# Use this file to prevent files from being overwritten by the generator. -# The patterns follow closely to .gitignore or .dockerignore. - -# As an example, the C# client generator defines ApiClient.cs. -# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: -#ApiClient.cs - -# You can match any string of characters against a directory, file or extension with a single asterisk (*): -#foo/*/qux -# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux - -# You can recursively match patterns against a directory, file or extension with a double asterisk (**): -#foo/**/qux -# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux - -# You can also negate patterns with an exclamation (!). -# For example, you can ignore all files in a docs folder with the file extension .md: -#docs/*.md -# Then explicitly reverse the ignore rule for a single file: -#!docs/README.md diff --git a/samples/client/petstore/powershell-experimental/.openapi-generator/VERSION b/samples/client/petstore/powershell-experimental/.openapi-generator/VERSION deleted file mode 100644 index b5d898602c2..00000000000 --- a/samples/client/petstore/powershell-experimental/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -4.3.1-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/powershell-experimental/Build.ps1 b/samples/client/petstore/powershell-experimental/Build.ps1 deleted file mode 100644 index 72aa4fe183b..00000000000 --- a/samples/client/petstore/powershell-experimental/Build.ps1 +++ /dev/null @@ -1,72 +0,0 @@ -# -# OpenAPI Petstore -# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. -# Version: 1.0.0 -# Generated by OpenAPI Generator: https://openapi-generator.tech -# - -function Get-FunctionsToExport { - [CmdletBinding()] - Param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] - [ValidateNotNullOrEmpty()] - [Alias('FullName')] - $Path - ) - - Process { - $Token = $null - $ParserErr = $null - - $Ast = [System.Management.Automation.Language.Parser]::ParseFile( - $Path, - [ref]$Token, - [ref]$ParserErr - ) - - if ($ParserErr) { - throw $ParserErr - } else { - foreach ($name in 'Begin', 'Process', 'End') { - foreach ($Statement in $Ast."${name}Block".Statements) { - if ( - [String]::IsNullOrWhiteSpace($Statement.Name) -or - $Statement.Extent.ToString() -notmatch - ('function\W+{0}' -f $Statement.Name) - ) { - continue - } - - $Statement.Name - } - } - } - } -} - -$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path -$FunctionPath = 'Api', 'Model', 'Client' | ForEach-Object {Join-Path "$ScriptDir\src\PSPetstore\" $_} - -$Manifest = @{ - Path = "$ScriptDir\src\PSPetstore\PSPetstore.psd1" - - Author = 'OpenAPI Generator Team' - CompanyName = 'openapitools.org' - Description = 'PSPetstore - the PowerShell module for OpenAPI Petstore' - - ModuleVersion = '0.1.2' - - RootModule = 'PSPetstore.psm1' - Guid = 'a27b908d-2a20-467f-bc32-af6f3a654ac5' # Has to be static, otherwise each new build will be considered different module - - PowerShellVersion = '3.0' - - FunctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-FunctionsToExport - - VariablesToExport = @() - AliasesToExport = @() - CmdletsToExport = @() - -} - -New-ModuleManifest @Manifest diff --git a/samples/client/petstore/powershell-experimental/README.md b/samples/client/petstore/powershell-experimental/README.md deleted file mode 100644 index 187e0543e42..00000000000 --- a/samples/client/petstore/powershell-experimental/README.md +++ /dev/null @@ -1,120 +0,0 @@ -# PSPetstore - the PowerShell module for the OpenAPI Petstore - -This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - -This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - -- API version: 1.0.0 -- SDK version: 0.1.2 -- Build package: org.openapitools.codegen.languages.PowerShellExperimentalClientCodegen - - -## Frameworks supported -- PowerShell 5.0 or later - - -## Dependencies - - -## Installation - -To install from PowerShell Gallery (https://www.powershellgallery.com/packages/PSPetstore) -```powershell -Import-Module -Name PSPetstore -Verbose -``` - -To install from the source, run the following command to build and install the PowerShell module locally: -```powershell -Build.ps1 -Import-Module -Name '.\src\PSPetstore' -Verbose -``` - -To avoid function name collision, one can use `-Prefix`, e.g. `Import-Module -Name '.\src\PSPetstore' -Prefix prefix` - -To uninstall the module, simply run: -```powershell -Remove-Module -FullyQualifiedName @{ModuleName = "PSPetstore"; ModuleVersion = "0.1.2"} -``` - - -## Tests - -To install and run `Pester`, please execute the following commands in the terminal: - -```powershell -Install-module -name Pester -force - -Invoker-Pester -``` - -For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debugging and disable it with `$DebugPreference = 'SilentlyContinue'` when done with the troubleshooting. - -## Documentation for API Endpoints - -All URIs are relative to *http://petstore.swagger.io:80/v2* - -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -*PSPetApi* | [**Add-PSPet**](docs/PSPetApi.md#Add-PSPet) | **POST** /pet | Add a new pet to the store -*PSPetApi* | [**Remove-Pet**](docs/PSPetApi.md#remove-pet) | **DELETE** /pet/{petId} | Deletes a pet -*PSPetApi* | [**Find-PSPetsByStatus**](docs/PSPetApi.md#Find-PSPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status -*PSPetApi* | [**Find-PSPetsByTags**](docs/PSPetApi.md#Find-PSPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags -*PSPetApi* | [**Get-PSPetById**](docs/PSPetApi.md#Get-PSPetById) | **GET** /pet/{petId} | Find pet by ID -*PSPetApi* | [**Update-PSPet**](docs/PSPetApi.md#Update-PSPet) | **PUT** /pet | Update an existing pet -*PSPetApi* | [**Update-PSPetWithForm**](docs/PSPetApi.md#Update-PSPetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data -*PSPetApi* | [**Invoke-PSUploadFile**](docs/PSPetApi.md#Invoke-PSUploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image -*PSStoreApi* | [**Remove-PSOrder**](docs/PSStoreApi.md#Remove-PSOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID -*PSStoreApi* | [**Get-PSInventory**](docs/PSStoreApi.md#Get-PSInventory) | **GET** /store/inventory | Returns pet inventories by status -*PSStoreApi* | [**Get-PSOrderById**](docs/PSStoreApi.md#Get-PSOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID -*PSStoreApi* | [**Invoke-PSPlaceOrder**](docs/PSStoreApi.md#Invoke-PSPlaceOrder) | **POST** /store/order | Place an order for a pet -*PSUserApi* | [**New-PSUser**](docs/PSUserApi.md#New-PSUser) | **POST** /user | Create user -*PSUserApi* | [**New-PSUsersWithArrayInput**](docs/PSUserApi.md#New-PSUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array -*PSUserApi* | [**New-PSUsersWithListInput**](docs/PSUserApi.md#New-PSUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array -*PSUserApi* | [**Remove-PSUser**](docs/PSUserApi.md#Remove-PSUser) | **DELETE** /user/{username} | Delete user -*PSUserApi* | [**Get-PSUserByName**](docs/PSUserApi.md#Get-PSUserByName) | **GET** /user/{username} | Get user by user name -*PSUserApi* | [**Invoke-PSLoginUser**](docs/PSUserApi.md#Invoke-PSLoginUser) | **GET** /user/login | Logs user into the system -*PSUserApi* | [**Invoke-PSLogoutUser**](docs/PSUserApi.md#Invoke-PSLogoutUser) | **GET** /user/logout | Logs out current logged in user session -*PSUserApi* | [**Update-PSUser**](docs/PSUserApi.md#Update-PSUser) | **PUT** /user/{username} | Updated user - - -## Documentation for Models - - - [PSPetstore/Model.ApiResponse](docs/ApiResponse.md) - - [PSPetstore/Model.Category](docs/Category.md) - - [PSPetstore/Model.InlineObject](docs/InlineObject.md) - - [PSPetstore/Model.InlineObject1](docs/InlineObject1.md) - - [PSPetstore/Model.Order](docs/Order.md) - - [PSPetstore/Model.Pet](docs/Pet.md) - - [PSPetstore/Model.Tag](docs/Tag.md) - - [PSPetstore/Model.User](docs/User.md) - - -## Documentation for Authorization - - -### api_key - -- **Type**: API key - -- **API key parameter name**: api_key -- **Location**: HTTP header - - -### auth_cookie - -- **Type**: API key - -- **API key parameter name**: AUTH_KEY -- **Location**: - - -### petstore_auth - - -- **Type**: OAuth -- **Flow**: implicit -- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog -- **Scopes**: - - write:pets: modify pets in your account - - read:pets: read your pets - diff --git a/samples/client/petstore/powershell/.openapi-generator/VERSION b/samples/client/petstore/powershell/.openapi-generator/VERSION index 58592f031f6..d99e7162d01 100644 --- a/samples/client/petstore/powershell/.openapi-generator/VERSION +++ b/samples/client/petstore/powershell/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.3-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/powershell/Build.ps1 b/samples/client/petstore/powershell/Build.ps1 index 3587b9d4b64..72aa4fe183b 100644 --- a/samples/client/petstore/powershell/Build.ps1 +++ b/samples/client/petstore/powershell/Build.ps1 @@ -1,3 +1,10 @@ +# +# OpenAPI Petstore +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# Version: 1.0.0 +# Generated by OpenAPI Generator: https://openapi-generator.tech +# + function Get-FunctionsToExport { [CmdletBinding()] Param ( @@ -38,51 +45,28 @@ function Get-FunctionsToExport { } $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path -$ClientPath = ("$ScriptDir\..\..\petstore\csharp\OpenAPIClient" | Resolve-Path).ProviderPath -$FunctionPath = 'API', 'Model' | ForEach-Object {Join-Path "$ScriptDir\src\Org.OpenAPITools\" $_} -$BinPath = "$ScriptDir\src\Org.OpenAPITools\Bin" - -Start-Process -FilePath "$ClientPath\build.bat" -WorkingDirectory $ClientPath -Wait -NoNewWindow - -if (!(Test-Path "$ScriptDir\src\Org.OpenAPITools\Bin" -PathType Container)) { - New-Item "$ScriptDir\src\Org.OpenAPITools\Bin" -ItemType Directory > $null -} - -Copy-Item "$ClientPath\bin\*.dll" $BinPath +$FunctionPath = 'Api', 'Model', 'Client' | ForEach-Object {Join-Path "$ScriptDir\src\PSPetstore\" $_} $Manifest = @{ - Path = "$ScriptDir\src\Org.OpenAPITools\Org.OpenAPITools.psd1" + Path = "$ScriptDir\src\PSPetstore\PSPetstore.psd1" Author = 'OpenAPI Generator Team' CompanyName = 'openapitools.org' - Description = 'Org.OpenAPITools - the PowerShell module for OpenAPI Petstore' + Description = 'PSPetstore - the PowerShell module for OpenAPI Petstore' - RootModule = 'Org.OpenAPITools.psm1' + ModuleVersion = '0.1.2' + + RootModule = 'PSPetstore.psm1' Guid = 'a27b908d-2a20-467f-bc32-af6f3a654ac5' # Has to be static, otherwise each new build will be considered different module PowerShellVersion = '3.0' - RequiredAssemblies = Get-ChildItem "$BinPath\*.dll" | ForEach-Object { - Join-Path $_.Directory.Name $_.Name - } - FunctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-FunctionsToExport VariablesToExport = @() AliasesToExport = @() CmdletsToExport = @() - # Should we use prefix to prevent command name collisions? - # https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/ - # - # Kirk Munro recommends against it: - # https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/#comment-20820 - # - # If not, we'd need to generate functions name with prefix. For examples, - # - # DefaultCommandPrefix = 'PetApi' - # DefaultCommandPrefix = 'StoreApi' - # DefaultCommandPrefix = 'UserApi' } New-ModuleManifest @Manifest diff --git a/samples/client/petstore/powershell/README.md b/samples/client/petstore/powershell/README.md index 5196860d730..6d3c70607d9 100644 --- a/samples/client/petstore/powershell/README.md +++ b/samples/client/petstore/powershell/README.md @@ -1,30 +1,120 @@ -# Org.OpenAPITools - the PowerShell module for the OpenAPI Petstore +# PSPetstore - the PowerShell module for the OpenAPI Petstore This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: 1.0.0 -- SDK version: +- SDK version: 0.1.2 - Build package: org.openapitools.codegen.languages.PowerShellClientCodegen ## Frameworks supported -- PowerShell 3.0 or later +- PowerShell 5.0 or later ## Dependencies -- C# API client generated by OpenAPI Generator AND should be located in $ScriptDir\..\..\petstore\csharp\OpenAPIClient as stated in Build.ps1 ## Installation -Run the following command to generate the DLL -- [Windows] `Build.ps1` -Then import module from the .\src\Org.OpenAPITools folder: +To install from PowerShell Gallery (https://www.powershellgallery.com/packages/PSPetstore) ```powershell -using Org.OpenAPITools.Org.OpenAPITools/API; -using Org.OpenAPITools.Client; -using Org.OpenAPITools.Org.OpenAPITools/Model; +Import-Module -Name PSPetstore -Verbose ``` +To install from the source, run the following command to build and install the PowerShell module locally: +```powershell +Build.ps1 +Import-Module -Name '.\src\PSPetstore' -Verbose +``` + +To avoid function name collision, one can use `-Prefix`, e.g. `Import-Module -Name '.\src\PSPetstore' -Prefix prefix` + +To uninstall the module, simply run: +```powershell +Remove-Module -FullyQualifiedName @{ModuleName = "PSPetstore"; ModuleVersion = "0.1.2"} +``` + + +## Tests + +To install and run `Pester`, please execute the following commands in the terminal: + +```powershell +Install-module -name Pester -force + +Invoker-Pester +``` + +For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debugging and disable it with `$DebugPreference = 'SilentlyContinue'` when done with the troubleshooting. + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PSPetApi* | [**Add-PSPet**](docs/PSPetApi.md#Add-PSPet) | **POST** /pet | Add a new pet to the store +*PSPetApi* | [**Remove-Pet**](docs/PSPetApi.md#remove-pet) | **DELETE** /pet/{petId} | Deletes a pet +*PSPetApi* | [**Find-PSPetsByStatus**](docs/PSPetApi.md#Find-PSPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status +*PSPetApi* | [**Find-PSPetsByTags**](docs/PSPetApi.md#Find-PSPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags +*PSPetApi* | [**Get-PSPetById**](docs/PSPetApi.md#Get-PSPetById) | **GET** /pet/{petId} | Find pet by ID +*PSPetApi* | [**Update-PSPet**](docs/PSPetApi.md#Update-PSPet) | **PUT** /pet | Update an existing pet +*PSPetApi* | [**Update-PSPetWithForm**](docs/PSPetApi.md#Update-PSPetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data +*PSPetApi* | [**Invoke-PSUploadFile**](docs/PSPetApi.md#Invoke-PSUploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image +*PSStoreApi* | [**Remove-PSOrder**](docs/PSStoreApi.md#Remove-PSOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*PSStoreApi* | [**Get-PSInventory**](docs/PSStoreApi.md#Get-PSInventory) | **GET** /store/inventory | Returns pet inventories by status +*PSStoreApi* | [**Get-PSOrderById**](docs/PSStoreApi.md#Get-PSOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +*PSStoreApi* | [**Invoke-PSPlaceOrder**](docs/PSStoreApi.md#Invoke-PSPlaceOrder) | **POST** /store/order | Place an order for a pet +*PSUserApi* | [**New-PSUser**](docs/PSUserApi.md#New-PSUser) | **POST** /user | Create user +*PSUserApi* | [**New-PSUsersWithArrayInput**](docs/PSUserApi.md#New-PSUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array +*PSUserApi* | [**New-PSUsersWithListInput**](docs/PSUserApi.md#New-PSUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array +*PSUserApi* | [**Remove-PSUser**](docs/PSUserApi.md#Remove-PSUser) | **DELETE** /user/{username} | Delete user +*PSUserApi* | [**Get-PSUserByName**](docs/PSUserApi.md#Get-PSUserByName) | **GET** /user/{username} | Get user by user name +*PSUserApi* | [**Invoke-PSLoginUser**](docs/PSUserApi.md#Invoke-PSLoginUser) | **GET** /user/login | Logs user into the system +*PSUserApi* | [**Invoke-PSLogoutUser**](docs/PSUserApi.md#Invoke-PSLogoutUser) | **GET** /user/logout | Logs out current logged in user session +*PSUserApi* | [**Update-PSUser**](docs/PSUserApi.md#Update-PSUser) | **PUT** /user/{username} | Updated user + + +## Documentation for Models + + - [PSPetstore/Model.ApiResponse](docs/ApiResponse.md) + - [PSPetstore/Model.Category](docs/Category.md) + - [PSPetstore/Model.InlineObject](docs/InlineObject.md) + - [PSPetstore/Model.InlineObject1](docs/InlineObject1.md) + - [PSPetstore/Model.Order](docs/Order.md) + - [PSPetstore/Model.Pet](docs/Pet.md) + - [PSPetstore/Model.Tag](docs/Tag.md) + - [PSPetstore/Model.User](docs/User.md) + + +## Documentation for Authorization + + +### api_key + +- **Type**: API key + +- **API key parameter name**: api_key +- **Location**: HTTP header + + +### auth_cookie + +- **Type**: API key + +- **API key parameter name**: AUTH_KEY +- **Location**: + + +### petstore_auth + + +- **Type**: OAuth +- **Flow**: implicit +- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog +- **Scopes**: + - write:pets: modify pets in your account + - read:pets: read your pets + diff --git a/samples/client/petstore/powershell-experimental/Test1.ps1 b/samples/client/petstore/powershell/Test1.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/Test1.ps1 rename to samples/client/petstore/powershell/Test1.ps1 diff --git a/samples/client/petstore/powershell-experimental/appveyor.yml b/samples/client/petstore/powershell/appveyor.yml similarity index 100% rename from samples/client/petstore/powershell-experimental/appveyor.yml rename to samples/client/petstore/powershell/appveyor.yml diff --git a/samples/client/petstore/powershell-experimental/docs/ApiResponse.md b/samples/client/petstore/powershell/docs/ApiResponse.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/ApiResponse.md rename to samples/client/petstore/powershell/docs/ApiResponse.md diff --git a/samples/client/petstore/powershell-experimental/docs/Category.md b/samples/client/petstore/powershell/docs/Category.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/Category.md rename to samples/client/petstore/powershell/docs/Category.md diff --git a/samples/client/petstore/powershell-experimental/docs/InlineObject.md b/samples/client/petstore/powershell/docs/InlineObject.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/InlineObject.md rename to samples/client/petstore/powershell/docs/InlineObject.md diff --git a/samples/client/petstore/powershell-experimental/docs/InlineObject1.md b/samples/client/petstore/powershell/docs/InlineObject1.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/InlineObject1.md rename to samples/client/petstore/powershell/docs/InlineObject1.md diff --git a/samples/client/petstore/powershell-experimental/docs/Order.md b/samples/client/petstore/powershell/docs/Order.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/Order.md rename to samples/client/petstore/powershell/docs/Order.md diff --git a/samples/client/petstore/powershell-experimental/docs/PSPetApi.md b/samples/client/petstore/powershell/docs/PSPetApi.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/PSPetApi.md rename to samples/client/petstore/powershell/docs/PSPetApi.md diff --git a/samples/client/petstore/powershell-experimental/docs/PSStoreApi.md b/samples/client/petstore/powershell/docs/PSStoreApi.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/PSStoreApi.md rename to samples/client/petstore/powershell/docs/PSStoreApi.md diff --git a/samples/client/petstore/powershell-experimental/docs/PSUserApi.md b/samples/client/petstore/powershell/docs/PSUserApi.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/PSUserApi.md rename to samples/client/petstore/powershell/docs/PSUserApi.md diff --git a/samples/client/petstore/powershell-experimental/docs/Pet.md b/samples/client/petstore/powershell/docs/Pet.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/Pet.md rename to samples/client/petstore/powershell/docs/Pet.md diff --git a/samples/client/petstore/powershell-experimental/docs/Tag.md b/samples/client/petstore/powershell/docs/Tag.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/Tag.md rename to samples/client/petstore/powershell/docs/Tag.md diff --git a/samples/client/petstore/powershell-experimental/docs/User.md b/samples/client/petstore/powershell/docs/User.md similarity index 100% rename from samples/client/petstore/powershell-experimental/docs/User.md rename to samples/client/petstore/powershell/docs/User.md diff --git a/samples/client/petstore/powershell-experimental/plus.gif b/samples/client/petstore/powershell/plus.gif similarity index 100% rename from samples/client/petstore/powershell-experimental/plus.gif rename to samples/client/petstore/powershell/plus.gif diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/API/PetApi.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/API/PetApi.ps1 deleted file mode 100644 index 9eb13d25847..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/API/PetApi.ps1 +++ /dev/null @@ -1,164 +0,0 @@ -function Invoke-PetApiAddPet { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.Pet] - ${body} - ) - - Process { - 'Calling method: PetApi-AddPet' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.AddPet( - ${body} - ) - } -} - -function Invoke-PetApiDeletePet { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Int64] - ${petId}, - [Parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] - [String] - ${apiKey} - ) - - Process { - 'Calling method: PetApi-DeletePet' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.DeletePet( - ${petId}, - ${apiKey} - ) - } -} - -function Invoke-PetApiFindPetsByStatus { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String[]] - ${status} - ) - - Process { - 'Calling method: PetApi-FindPetsByStatus' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.FindPetsByStatus( - ${status} - ) - } -} - -function Invoke-PetApiFindPetsByTags { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String[]] - ${tags} - ) - - Process { - 'Calling method: PetApi-FindPetsByTags' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.FindPetsByTags( - ${tags} - ) - } -} - -function Invoke-PetApiGetPetById { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Int64] - ${petId} - ) - - Process { - 'Calling method: PetApi-GetPetById' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.GetPetById( - ${petId} - ) - } -} - -function Invoke-PetApiUpdatePet { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.Pet] - ${body} - ) - - Process { - 'Calling method: PetApi-UpdatePet' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.UpdatePet( - ${body} - ) - } -} - -function Invoke-PetApiUpdatePetWithForm { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Int64] - ${petId}, - [Parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] - [String] - ${name}, - [Parameter(Position = 2, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] - [String] - ${status} - ) - - Process { - 'Calling method: PetApi-UpdatePetWithForm' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.UpdatePetWithForm( - ${petId}, - ${name}, - ${status} - ) - } -} - -function Invoke-PetApiUploadFile { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Int64] - ${petId}, - [Parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] - [String] - ${additionalMetadata}, - [Parameter(Position = 2, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] - [String] - ${file} - ) - - Process { - 'Calling method: PetApi-UploadFile' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:PetApi.UploadFile( - ${petId}, - ${additionalMetadata}, - ${file} - ) - } -} - diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/API/StoreApi.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/API/StoreApi.ps1 deleted file mode 100644 index 679176f56a2..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/API/StoreApi.ps1 +++ /dev/null @@ -1,68 +0,0 @@ -function Invoke-StoreApiDeleteOrder { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${orderId} - ) - - Process { - 'Calling method: StoreApi-DeleteOrder' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:StoreApi.DeleteOrder( - ${orderId} - ) - } -} - -function Invoke-StoreApiGetInventory { - [CmdletBinding()] - Param ( - ) - - Process { - 'Calling method: StoreApi-GetInventory' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:StoreApi.GetInventory( - ) - } -} - -function Invoke-StoreApiGetOrderById { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Int64] - ${orderId} - ) - - Process { - 'Calling method: StoreApi-GetOrderById' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:StoreApi.GetOrderById( - ${orderId} - ) - } -} - -function Invoke-StoreApiPlaceOrder { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.Order] - ${body} - ) - - Process { - 'Calling method: StoreApi-PlaceOrder' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:StoreApi.PlaceOrder( - ${body} - ) - } -} - diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/API/UserApi.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/API/UserApi.ps1 deleted file mode 100644 index d8eea661dcc..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/API/UserApi.ps1 +++ /dev/null @@ -1,148 +0,0 @@ -function Invoke-UserApiCreateUser { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.User] - ${body} - ) - - Process { - 'Calling method: UserApi-CreateUser' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.CreateUser( - ${body} - ) - } -} - -function Invoke-UserApiCreateUsersWithArrayInput { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.User[]] - ${body} - ) - - Process { - 'Calling method: UserApi-CreateUsersWithArrayInput' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.CreateUsersWithArrayInput( - ${body} - ) - } -} - -function Invoke-UserApiCreateUsersWithListInput { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.User[]] - ${body} - ) - - Process { - 'Calling method: UserApi-CreateUsersWithListInput' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.CreateUsersWithListInput( - ${body} - ) - } -} - -function Invoke-UserApiDeleteUser { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${username} - ) - - Process { - 'Calling method: UserApi-DeleteUser' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.DeleteUser( - ${username} - ) - } -} - -function Invoke-UserApiGetUserByName { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${username} - ) - - Process { - 'Calling method: UserApi-GetUserByName' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.GetUserByName( - ${username} - ) - } -} - -function Invoke-UserApiLoginUser { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${username}, - [Parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${password} - ) - - Process { - 'Calling method: UserApi-LoginUser' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.LoginUser( - ${username}, - ${password} - ) - } -} - -function Invoke-UserApiLogoutUser { - [CmdletBinding()] - Param ( - ) - - Process { - 'Calling method: UserApi-LogoutUser' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.LogoutUser( - ) - } -} - -function Invoke-UserApiUpdateUser { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${username}, - [Parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [Org.OpenAPITools.Model.User] - ${body} - ) - - Process { - 'Calling method: UserApi-UpdateUser' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - $Script:UserApi.UpdateUser( - ${username}, - ${body} - ) - } -} - diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-ApiResponse.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-ApiResponse.ps1 deleted file mode 100644 index deab379454f..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-ApiResponse.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -function New-ApiResponse { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int32]] - ${code}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [String] - ${type}, - [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)] - [String] - ${message} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.ApiResponse' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.ApiResponse -ArgumentList @( - ${code}, - ${type}, - ${message} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Category.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Category.ps1 deleted file mode 100644 index b6b263f54cf..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Category.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -function New-Category { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int64]] - ${id}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [String] - ${name} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.Category' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.Category -ArgumentList @( - ${id}, - ${name} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject.ps1 deleted file mode 100644 index cdab2d989a3..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -function New-InlineObject { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [String] - ${name}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [String] - ${status} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.InlineObject' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.InlineObject -ArgumentList @( - ${name}, - ${status} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject1.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject1.ps1 deleted file mode 100644 index 0293b3068a4..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-InlineObject1.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -function New-InlineObject1 { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [String] - ${additionalMetadata}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[String]] - ${file} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.InlineObject1' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.InlineObject1 -ArgumentList @( - ${additionalMetadata}, - ${file} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Order.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Order.ps1 deleted file mode 100644 index 3393772475f..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Order.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -function New-Order { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int64]] - ${id}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int64]] - ${petId}, - [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int32]] - ${quantity}, - [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[System.DateTime]] - ${shipDate}, - [Parameter(Position = 4, ValueFromPipelineByPropertyName = $true)] - [String] - ${status}, - [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Boolean]] - ${complete} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.Order' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.Order -ArgumentList @( - ${id}, - ${petId}, - ${quantity}, - ${shipDate}, - ${status}, - ${complete} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Pet.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Pet.ps1 deleted file mode 100644 index 27f0f8a42d9..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Pet.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -function New-Pet { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int64]] - ${id}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [Org.OpenAPITools.Model.Category] - ${category}, - [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String] - ${name}, - [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] - [String[]] - ${photoUrls}, - [Parameter(Position = 4, ValueFromPipelineByPropertyName = $true)] - [Org.OpenAPITools.Model.Tag[]] - ${tags}, - [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)] - [String] - ${status} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.Pet' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.Pet -ArgumentList @( - ${id}, - ${category}, - ${name}, - ${photoUrls}, - ${tags}, - ${status} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Tag.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Tag.ps1 deleted file mode 100644 index e12f28e4533..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-Tag.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -function New-Tag { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int64]] - ${id}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [String] - ${name} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.Tag' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.Tag -ArgumentList @( - ${id}, - ${name} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-User.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-User.ps1 deleted file mode 100644 index 1b3ae9b1ca4..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Model/New-User.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -function New-User { - [CmdletBinding()] - Param ( - [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int64]] - ${id}, - [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] - [String] - ${username}, - [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)] - [String] - ${firstName}, - [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true)] - [String] - ${lastName}, - [Parameter(Position = 4, ValueFromPipelineByPropertyName = $true)] - [String] - ${email}, - [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)] - [String] - ${password}, - [Parameter(Position = 6, ValueFromPipelineByPropertyName = $true)] - [String] - ${phone}, - [Parameter(Position = 7, ValueFromPipelineByPropertyName = $true)] - [System.Nullable[Int32]] - ${userStatus} - ) - - Process { - 'Creating object: Org.OpenAPITools.Model.User' | Write-Verbose - $PSBoundParameters | Out-DebugParameter | Write-Debug - - New-Object -TypeName Org.OpenAPITools.Model.User -ArgumentList @( - ${id}, - ${username}, - ${firstName}, - ${lastName}, - ${email}, - ${password}, - ${phone}, - ${userStatus} - ) - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psd1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psd1 deleted file mode 100644 index 450e5162d65..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psd1 +++ /dev/null @@ -1,136 +0,0 @@ -# -# Module manifest for module 'Org.OpenAPITools' -# -# Generated by: OpenAPI Generator Team -# -# Generated on: 3/29/20 -# - -@{ - -# Script module or binary module file associated with this manifest. -RootModule = 'Org.OpenAPITools.psm1' - -# Version number of this module. -ModuleVersion = '0.0.1' - -# Supported PSEditions -# CompatiblePSEditions = @() - -# ID used to uniquely identify this module -GUID = 'a27b908d-2a20-467f-bc32-af6f3a654ac5' - -# Author of this module -Author = 'OpenAPI Generator Team' - -# Company or vendor of this module -CompanyName = 'openapitools.org' - -# Copyright statement for this module -Copyright = '(c) OpenAPI Generator Team. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'Org.OpenAPITools - the PowerShell module for OpenAPI Petstore' - -# Minimum version of the PowerShell engine required by this module -PowerShellVersion = '3.0' - -# Name of the PowerShell host required by this module -# PowerShellHostName = '' - -# Minimum version of the PowerShell host required by this module -# PowerShellHostVersion = '' - -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' - -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' - -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' - -# Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() - -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() - -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() - -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() - -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() - -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() - -# Functions 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 functions to export. -FunctionsToExport = 'Invoke-PetApiAddPet', 'Invoke-PetApiDeletePet', - 'Invoke-PetApiFindPetsByStatus', 'Invoke-PetApiFindPetsByTags', - 'Invoke-PetApiGetPetById', 'Invoke-PetApiUpdatePet', - 'Invoke-PetApiUpdatePetWithForm', 'Invoke-PetApiUploadFile', - 'Invoke-StoreApiDeleteOrder', 'Invoke-StoreApiGetInventory', - 'Invoke-StoreApiGetOrderById', 'Invoke-StoreApiPlaceOrder', - 'Invoke-UserApiCreateUser', - 'Invoke-UserApiCreateUsersWithArrayInput', - 'Invoke-UserApiCreateUsersWithListInput', - 'Invoke-UserApiDeleteUser', 'Invoke-UserApiGetUserByName', - 'Invoke-UserApiLoginUser', 'Invoke-UserApiLogoutUser', - 'Invoke-UserApiUpdateUser', 'New-ApiResponse', 'New-Category', - 'New-InlineObject', 'New-InlineObject1', 'New-Order', 'New-Pet', - 'New-Tag', 'New-User' - -# 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 = @() - -# Variables to export from this module -# VariablesToExport = @() - -# Aliases 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 aliases to export. -AliasesToExport = @() - -# DSC resources to export from this module -# DscResourcesToExport = @() - -# List of all modules packaged with this module -# ModuleList = @() - -# List of all files packaged with this module -# FileList = @() - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() - - # A URL to the license for this module. - # LicenseUri = '' - - # A URL to the main website for this project. - # ProjectUri = '' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - # ReleaseNotes = '' - - } # End of PSData hashtable - -} # End of PrivateData hashtable - -# HelpInfo URI of this module -# HelpInfoURI = '' - -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' - -} - diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psm1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psm1 deleted file mode 100644 index ef4b45fea95..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Org.OpenAPITools.psm1 +++ /dev/null @@ -1,29 +0,0 @@ -#region Import functions - -'API', 'Model', 'Private' | Get-ChildItem -Path { - Join-Path $PSScriptRoot $_ -} -Filter '*.ps1' | ForEach-Object { - Write-Verbose "Importing file: $($_.BaseName)" - try { - . $_.FullName - } catch { - Write-Verbose "Can't import function!" - } -} - -#endregion - - -#region Initialize APIs - -'Creating object: Org.OpenAPITools.Api.PetApi' | Write-Verbose -$Script:PetApi= New-Object -TypeName Org.OpenAPITools.Api.PetApi -ArgumentList @($null) - -'Creating object: Org.OpenAPITools.Api.StoreApi' | Write-Verbose -$Script:StoreApi= New-Object -TypeName Org.OpenAPITools.Api.StoreApi -ArgumentList @($null) - -'Creating object: Org.OpenAPITools.Api.UserApi' | Write-Verbose -$Script:UserApi= New-Object -TypeName Org.OpenAPITools.Api.UserApi -ArgumentList @($null) - - -#endregion diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Get-CommonParameters.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Get-CommonParameters.ps1 deleted file mode 100644 index 31a0a1ff3af..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Get-CommonParameters.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -<# -.Synopsis - Helper function to get common parameters (Verbose, Debug, etc.) -.Example - Get-CommonParameters -#> -function Get-CommonParameters { - function tmp { - [CmdletBinding()] - Param () - } - - (Get-Command -Name tmp -CommandType Function).Parameters.Keys -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Out-DebugParameter.ps1 b/samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Out-DebugParameter.ps1 deleted file mode 100644 index ca18c391cc1..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/Private/Out-DebugParameter.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -<# -.Synopsis - Helper function to format debug parameter output. -.Example - $PSBoundParameters | Out-DebugParameter | Write-Debug -#> -function Out-DebugParameter { - [CmdletBinding()] - Param ( - [Parameter(ValueFromPipeline = $true, Mandatory = $true)] - [AllowEmptyCollection()] - $InputObject - ) - - Begin { - $CommonParameters = Get-CommonParameters - } - - Process { - $InputObject.GetEnumerator() | Where-Object { - $CommonParameters -notcontains $_.Key - } | Format-Table -AutoSize -Property ( - @{ - Name = 'Parameter' - Expression = {$_.Key} - }, - @{ - Name = 'Value' - Expression = {$_.Value} - } - ) | Out-String -Stream | ForEach-Object { - if ($_.Trim()) { - $_ - } - } - } -} diff --git a/samples/client/petstore/powershell/src/Org.OpenAPITools/en-US/about_Org.OpenAPITools.help.txt b/samples/client/petstore/powershell/src/Org.OpenAPITools/en-US/about_Org.OpenAPITools.help.txt deleted file mode 100644 index 30b698470f1..00000000000 --- a/samples/client/petstore/powershell/src/Org.OpenAPITools/en-US/about_Org.OpenAPITools.help.txt +++ /dev/null @@ -1,19 +0,0 @@ -PSTOPIC - about_Org.OpenAPITools - -SHORT DESCRIPTION - Org.OpenAPITools - the PowerShell module for the OpenAPI Petstore - -LONG DESCRIPTION - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - - - API version: 1.0.0 - - SDK version: - - Build package: org.openapitools.codegen.languages.PowerShellClientCodegen - - Frameworks supported: - - * PowerShell 3.0+ - * .NET 4.0 or later diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/API/PSPetApi.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/API/PSPetApi.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/API/PSStoreApi.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/API/PSStoreApi.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/API/PSUserApi.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/API/PSUserApi.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Client/PSConfiguration.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/ApiResponse.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/ApiResponse.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/ApiResponse.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/ApiResponse.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Category.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Category.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Category.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/Category.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/InlineObject.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/InlineObject.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/InlineObject1.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject1.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/InlineObject1.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject1.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Order.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Order.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Pet.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Pet.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Tag.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Tag.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Tag.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/Tag.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/User.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/User.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Model/User.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Model/User.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1 b/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1 rename to samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psm1 b/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psm1 rename to samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psm1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Private/Get-CommonParameters.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Private/Get-CommonParameters.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Private/Get-CommonParameters.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Private/Get-CommonParameters.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Private/Out-DebugParameter.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Private/Out-DebugParameter.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Private/Out-DebugParameter.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Private/Out-DebugParameter.ps1 diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Private/PSApiClient.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 similarity index 91% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/Private/PSApiClient.ps1 rename to samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 index e965758e23a..ccb7529dc8d 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/Private/PSApiClient.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Private/PSApiClient.ps1 @@ -95,6 +95,21 @@ function Invoke-PSApiClient { $RequestBody = $Body } +# http signature authentication + if ($null -ne $Configuration['ApiKey'] -and $Configuration['ApiKey'].Count -gt 0) { + $httpSignHeaderArgument = @{ + Method = $Method + UriBuilder = $UriBuilder + Body = $Body + } + $signedHeader = Get-PSHttpSignedHeader @httpSignHeaderArgument + if($null -ne $signedHeader -and $signedHeader.Count -gt 0){ + foreach($item in $signedHeader.GetEnumerator()){ + $HeaderParameters[$item.Name] = $item.Value + } + } + } + if ($SkipCertificateCheck -eq $true) { $Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` -Method $Method ` diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/en-US/about_PSPetstore.help.txt b/samples/client/petstore/powershell/src/PSPetstore/en-US/about_PSPetstore.help.txt similarity index 95% rename from samples/client/petstore/powershell-experimental/src/PSPetstore/en-US/about_PSPetstore.help.txt rename to samples/client/petstore/powershell/src/PSPetstore/en-US/about_PSPetstore.help.txt index 040de6f9948..c35d0e44240 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/en-US/about_PSPetstore.help.txt +++ b/samples/client/petstore/powershell/src/PSPetstore/en-US/about_PSPetstore.help.txt @@ -11,7 +11,7 @@ LONG DESCRIPTION - API version: 1.0.0 - SDK version: 0.1.2 - - Build package: org.openapitools.codegen.languages.PowerShellExperimentalClientCodegen + - Build package: org.openapitools.codegen.languages.PowerShellClientCodegen Frameworks supported: diff --git a/samples/client/petstore/powershell/test/ApiResponseTest.ps1 b/samples/client/petstore/powershell/test/ApiResponseTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/ApiResponseTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/CategoryTest.ps1 b/samples/client/petstore/powershell/test/CategoryTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/CategoryTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/InlineObject1Test.ps1 b/samples/client/petstore/powershell/test/InlineObject1Test.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/InlineObject1Test.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/InlineObjectTest.ps1 b/samples/client/petstore/powershell/test/InlineObjectTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/InlineObjectTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/OrderTest.ps1 b/samples/client/petstore/powershell/test/OrderTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/OrderTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/PetApiTest.ps1 b/samples/client/petstore/powershell/test/PetApiTest.ps1 deleted file mode 100644 index bffda1b2248..00000000000 --- a/samples/client/petstore/powershell/test/PetApiTest.ps1 +++ /dev/null @@ -1,69 +0,0 @@ -# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech) -# Please replace "TEST_VALUE" with a proper value and uncomment the code for testing the function - -Describe 'Org.OpenAPITools PetApi' { - Context 'PetApi' { - It 'Invoke-PetApiAddPet' { - $ret = Invoke-PetApiGetPetById -pet "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiDeletePet' { - $ret = Invoke-PetApiGetPetById -petId "TEST_VALUE" -apiKey "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiFindPetsByStatus' { - $ret = Invoke-PetApiGetPetById -status "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiFindPetsByTags' { - $ret = Invoke-PetApiGetPetById -tags "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiGetPetById' { - $ret = Invoke-PetApiGetPetById -petId "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiUpdatePet' { - $ret = Invoke-PetApiGetPetById -pet "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiUpdatePetWithForm' { - $ret = Invoke-PetApiGetPetById -petId "TEST_VALUE" -name "TEST_VALUE" -status "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'PetApi' { - It 'Invoke-PetApiUploadFile' { - $ret = Invoke-PetApiGetPetById -petId "TEST_VALUE" -additionalMetadata "TEST_VALUE" -file "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - -} diff --git a/samples/client/petstore/powershell/test/PetTest.ps1 b/samples/client/petstore/powershell/test/PetTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/PetTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/StoreApiTest.ps1 b/samples/client/petstore/powershell/test/StoreApiTest.ps1 deleted file mode 100644 index 960c8215358..00000000000 --- a/samples/client/petstore/powershell/test/StoreApiTest.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech) -# Please replace "TEST_VALUE" with a proper value and uncomment the code for testing the function - -Describe 'Org.OpenAPITools StoreApi' { - Context 'StoreApi' { - It 'Invoke-StoreApiDeleteOrder' { - $ret = Invoke-PetApiGetPetById -orderId "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'StoreApi' { - It 'Invoke-StoreApiGetInventory' { - $ret = Invoke-PetApiGetPetById - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'StoreApi' { - It 'Invoke-StoreApiGetOrderById' { - $ret = Invoke-PetApiGetPetById -orderId "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'StoreApi' { - It 'Invoke-StoreApiPlaceOrder' { - $ret = Invoke-PetApiGetPetById -order "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - -} diff --git a/samples/client/petstore/powershell/test/TagTest.ps1 b/samples/client/petstore/powershell/test/TagTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/TagTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell/test/UserApiTest.ps1 b/samples/client/petstore/powershell/test/UserApiTest.ps1 deleted file mode 100644 index e0faf719a49..00000000000 --- a/samples/client/petstore/powershell/test/UserApiTest.ps1 +++ /dev/null @@ -1,69 +0,0 @@ -# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech) -# Please replace "TEST_VALUE" with a proper value and uncomment the code for testing the function - -Describe 'Org.OpenAPITools UserApi' { - Context 'UserApi' { - It 'Invoke-UserApiCreateUser' { - $ret = Invoke-PetApiGetPetById -user "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiCreateUsersWithArrayInput' { - $ret = Invoke-PetApiGetPetById -user "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiCreateUsersWithListInput' { - $ret = Invoke-PetApiGetPetById -user "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiDeleteUser' { - $ret = Invoke-PetApiGetPetById -username "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiGetUserByName' { - $ret = Invoke-PetApiGetPetById -username "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiLoginUser' { - $ret = Invoke-PetApiGetPetById -username "TEST_VALUE" -password "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiLogoutUser' { - $ret = Invoke-PetApiGetPetById - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - - Context 'UserApi' { - It 'Invoke-UserApiUpdateUser' { - $ret = Invoke-PetApiGetPetById -username "TEST_VALUE" -user "TEST_VALUE" - #$ret | Should BeOfType Org.OpenAPITools.Model.ModelNameHere - #$ret.property | Should Be 0 - } - } - -} diff --git a/samples/client/petstore/powershell/test/UserTest.ps1 b/samples/client/petstore/powershell/test/UserTest.ps1 deleted file mode 100644 index 1fc8f6add42..00000000000 --- a/samples/client/petstore/powershell/test/UserTest.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -## TODO we need to update the template to test the model files - diff --git a/samples/client/petstore/powershell-experimental/tests/Api/PSPetApi.Tests.ps1 b/samples/client/petstore/powershell/tests/Api/PSPetApi.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Api/PSPetApi.Tests.ps1 rename to samples/client/petstore/powershell/tests/Api/PSPetApi.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Api/PSStoreApi.Tests.ps1 b/samples/client/petstore/powershell/tests/Api/PSStoreApi.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Api/PSStoreApi.Tests.ps1 rename to samples/client/petstore/powershell/tests/Api/PSStoreApi.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Api/PSUserApi.Tests.ps1 b/samples/client/petstore/powershell/tests/Api/PSUserApi.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Api/PSUserApi.Tests.ps1 rename to samples/client/petstore/powershell/tests/Api/PSUserApi.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/ApiResponse.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/ApiResponse.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/ApiResponse.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/ApiResponse.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/Category.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/Category.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/Category.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/Category.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/InlineObject.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/InlineObject.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/InlineObject.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/InlineObject.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/InlineObject1.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/InlineObject1.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/InlineObject1.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/InlineObject1.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/Order.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/Order.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/Order.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/Order.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/Pet.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/Pet.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/Pet.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/Pet.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/Tag.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/Tag.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/Tag.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/Tag.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Model/User.Tests.ps1 b/samples/client/petstore/powershell/tests/Model/User.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Model/User.Tests.ps1 rename to samples/client/petstore/powershell/tests/Model/User.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1 b/samples/client/petstore/powershell/tests/Petstore.Tests.ps1 similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1 rename to samples/client/petstore/powershell/tests/Petstore.Tests.ps1 diff --git a/samples/client/petstore/powershell-experimental/tests/plus.gif b/samples/client/petstore/powershell/tests/plus.gif similarity index 100% rename from samples/client/petstore/powershell-experimental/tests/plus.gif rename to samples/client/petstore/powershell/tests/plus.gif