From 57eb1a0fcf1d3112ea8b5a4f0a59e8def68c6118 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 23 Mar 2020 15:18:17 +0800 Subject: [PATCH] [PowerShell] Fix map type (#5638) * fix map type * remove output type, fix appveyor * test macos * comment out failing scala test * fix typo: configuration * Revert "comment out failing scala test" This reverts commit 1dcf84ffcbb7ab520938ae7c75d60a8329f71478. --- .../PowerShellExperimentalClientCodegen.java | 4 +--- .../powershell-experimental/api.mustache | 3 +-- .../powershell-experimental/appveyor.mustache | 6 +++-- .../powershell-experimental/appveyor.yml | 6 +++-- .../docs/PSStoreApi.md | 6 ++--- .../src/PSPetstore/API/PSPetApi.ps1 | 24 +++++++------------ .../src/PSPetstore/API/PSStoreApi.ps1 | 14 ++++------- .../src/PSPetstore/API/PSUserApi.ps1 | 24 +++++++------------ 8 files changed, 34 insertions(+), 53 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java index 6e9b95aa4167..b2ba94fb27f9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java @@ -548,9 +548,7 @@ public String getTypeDeclaration(Schema p) { 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 "Hashtable"; } else if (!languageSpecificPrimitives.contains(getSchemaType(p))) { return super.getTypeDeclaration(p); } diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache index 5d49e5ef522c..60955ee86613 100644 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache +++ b/modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache @@ -2,7 +2,6 @@ {{#operations}} {{#operation}} function {{{vendorExtensions.x-powershell-method-name}}} { -    [OutputType({{#returnType}}"{{{.}}}"{{/returnType}}{{^returnType}}[System.Void]{{/returnType}})] [CmdletBinding()] Param ( {{#allParams}} @@ -27,7 +26,7 @@ function {{{vendorExtensions.x-powershell-method-name}}} { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-{{{apiNamePrefix}}}Configuration + $Configuration = Get-{{{apiNamePrefix}}}Configuration {{#hasProduces}} # HTTP header 'Accept' (if needed) $LocalVarAccepts = @({{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}) diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/appveyor.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/appveyor.mustache index f808ee4a9cf5..eb11fbdc1890 100644 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/appveyor.mustache +++ b/modules/openapi-generator/src/main/resources/powershell-experimental/appveyor.mustache @@ -1,9 +1,11 @@ {{> partial_header}} version: 1.0.{build} image: - - Visual Studio 2017 - - Ubuntu + - Visual Studio 2017 # PS 5.x + - Ubuntu # PS 6.x + - macOS # PS 6.x install: + - ps: $PSVersionTable.PSVersion - ps: Install-Module Pester -Force -Scope CurrentUser build: off test_script: diff --git a/samples/client/petstore/powershell-experimental/appveyor.yml b/samples/client/petstore/powershell-experimental/appveyor.yml index 7652f202b97a..683e42df384e 100644 --- a/samples/client/petstore/powershell-experimental/appveyor.yml +++ b/samples/client/petstore/powershell-experimental/appveyor.yml @@ -7,9 +7,11 @@ version: 1.0.{build} image: - - Visual Studio 2017 - - Ubuntu + - Visual Studio 2017 # PS 5.x + - Ubuntu # PS 6.x + - macOS # PS 6.x install: + - ps: $PSVersionTable.PSVersion - ps: Install-Module Pester -Force -Scope CurrentUser build: off test_script: diff --git a/samples/client/petstore/powershell-experimental/docs/PSStoreApi.md b/samples/client/petstore/powershell-experimental/docs/PSStoreApi.md index a392f8f7553d..b9610344c8db 100644 --- a/samples/client/petstore/powershell-experimental/docs/PSStoreApi.md +++ b/samples/client/petstore/powershell-experimental/docs/PSStoreApi.md @@ -57,7 +57,7 @@ No authorization required # **Get-PSInventory** -> {String, Int32} Get-PSInventory
+> Hashtable Get-PSInventory
Returns pet inventories by status @@ -76,7 +76,7 @@ $Configuration["ApiKey"]["api_key"] = "YOUR_API_KEY" # Returns pet inventories by status try { - {String, Int32} $Result = Get-PSInventory + Hashtable $Result = Get-PSInventory } catch { Write-Host ($_.ErrorDetails | ConvertFrom-Json) Write-Host ($_.Exception.Response.Headers | ConvertTo-Json) @@ -88,7 +88,7 @@ This endpoint does not need any parameter. ### Return type -**{String, Int32}** +**Hashtable** ### Authorization diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1 index 360cb48e0cb6..7bbc0128145c 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1 @@ -6,7 +6,6 @@ # function Add-PSPet { -    [OutputType("Pet")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -27,7 +26,7 @@ function Add-PSPet { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -59,7 +58,6 @@ function Add-PSPet { } function Remove-Pet { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -83,7 +81,7 @@ function Remove-Pet { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration $LocalVarUri = '/pet/{petId}' if (!$PetId) { throw "Error! The required parameter `PetId` missing when calling deletePet." @@ -111,7 +109,6 @@ function Remove-Pet { } function Find-PSPetsByStatus { -    [OutputType("Pet[]")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -132,7 +129,7 @@ function Find-PSPetsByStatus { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -160,7 +157,6 @@ function Find-PSPetsByStatus { } function Find-PSPetsByTags { -    [OutputType("Pet[]")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -181,7 +177,7 @@ function Find-PSPetsByTags { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -209,7 +205,6 @@ function Find-PSPetsByTags { } function Get-PSPetById { -    [OutputType("Pet")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -230,7 +225,7 @@ function Get-PSPetById { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -260,7 +255,6 @@ function Get-PSPetById { } function Update-PSPet { -    [OutputType("Pet")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -281,7 +275,7 @@ function Update-PSPet { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -313,7 +307,6 @@ function Update-PSPet { } function Update-PSPetWithForm { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -340,7 +333,7 @@ function Update-PSPetWithForm { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Content-Type' $LocalVarContentTypes = @('application/x-www-form-urlencoded') @@ -375,7 +368,6 @@ function Update-PSPetWithForm { } function Invoke-PSUploadFile { -    [OutputType("ApiResponse")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -402,7 +394,7 @@ function Invoke-PSUploadFile { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/json') diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1 index 0b1404b377b1..3dfb8c00d6b1 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1 @@ -6,7 +6,6 @@ # function Invoke-PSDeleteOrder { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -27,7 +26,7 @@ function Invoke-PSDeleteOrder { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration $LocalVarUri = '/store/order/{orderId}' if (!$OrderId) { throw "Error! The required parameter `OrderId` missing when calling deleteOrder." @@ -50,7 +49,6 @@ function Invoke-PSDeleteOrder { } function Get-PSInventory { -    [OutputType("{String, Int32}")] [CmdletBinding()] Param ( ) @@ -68,7 +66,7 @@ function Get-PSInventory { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/json') @@ -87,14 +85,13 @@ function Get-PSInventory { -QueryParameters $LocalVarQueryParameters ` -FormParameters $LocalVarFormParameters ` -CookieParameters $LocalVarCookieParameters ` - -ReturnType "{String, Int32}" + -ReturnType "Hashtable" return $LocalVarResult["Response"] } } function Get-PSOrderById { -    [OutputType("Order")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -115,7 +112,7 @@ function Get-PSOrderById { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -141,7 +138,6 @@ function Get-PSOrderById { } function Invoke-PSPlaceOrder { -    [OutputType("Order")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -162,7 +158,7 @@ function Invoke-PSPlaceOrder { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1 index ebb0b548f109..f6b2d3ae67ad 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1 @@ -6,7 +6,6 @@ # function Invoke-PSCreateUser { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -27,7 +26,7 @@ function Invoke-PSCreateUser { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Content-Type' $LocalVarContentTypes = @('application/json') @@ -59,7 +58,6 @@ function Invoke-PSCreateUser { } function Invoke-PSCreateUsersWithArrayInput { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -80,7 +78,7 @@ function Invoke-PSCreateUsersWithArrayInput { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Content-Type' $LocalVarContentTypes = @('application/json') @@ -112,7 +110,6 @@ function Invoke-PSCreateUsersWithArrayInput { } function Invoke-PSCreateUsersWithListInput { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -133,7 +130,7 @@ function Invoke-PSCreateUsersWithListInput { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Content-Type' $LocalVarContentTypes = @('application/json') @@ -165,7 +162,6 @@ function Invoke-PSCreateUsersWithListInput { } function Invoke-PSDeleteUser { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -186,7 +182,7 @@ function Invoke-PSDeleteUser { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration $LocalVarUri = '/user/{username}' if (!$Username) { throw "Error! The required parameter `Username` missing when calling deleteUser." @@ -213,7 +209,6 @@ function Invoke-PSDeleteUser { } function Get-PSUserByName { -    [OutputType("User")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -234,7 +229,7 @@ function Get-PSUserByName { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -260,7 +255,6 @@ function Get-PSUserByName { } function Invoke-PSLoginUser { -    [OutputType("String")] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -284,7 +278,7 @@ function Invoke-PSLoginUser { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Accept' (if needed) $LocalVarAccepts = @('application/xml', 'application/json') @@ -316,7 +310,6 @@ function Invoke-PSLoginUser { } function Invoke-PSLogoutUser { -    [OutputType([System.Void])] [CmdletBinding()] Param ( ) @@ -334,7 +327,7 @@ function Invoke-PSLogoutUser { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration $LocalVarUri = '/user/logout' if ($Configuration["Cookie"]) { @@ -357,7 +350,6 @@ function Invoke-PSLogoutUser { } function Update-PSUser { -    [OutputType([System.Void])] [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)] @@ -381,7 +373,7 @@ function Update-PSUser { $LocalVarCookieParameters = @{} $LocalVarBodyParameter - $Configuraiton = Get-PSConfiguration + $Configuration = Get-PSConfiguration # HTTP header 'Content-Type' $LocalVarContentTypes = @('application/json')