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 8581afb94138..889940429074 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 @@ -1019,4 +1019,9 @@ private String toMethodName(String operationId) { // not using powershell verb return "Invoke-" + apiNamePrefix + methodName; } + + @Override + public String toRegularExpression(String pattern) { + return escapeText(pattern); + } } diff --git a/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache b/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache index c050cc30593c..81d5dba1324a 100644 --- a/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache @@ -24,7 +24,15 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} { [CmdletBinding()] Param ( {{#allVars}} - [Parameter(Position = {{vendorExtensions.x-index}}, ValueFromPipelineByPropertyName = $true{{#required}}, Mandatory = $true{{/required}})] + [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%> @@ -36,6 +44,54 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} { '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>> diff --git a/samples/client/petstore/powershell-experimental/Test1.ps1 b/samples/client/petstore/powershell-experimental/Test1.ps1 index 268665d81b1f..2c6ab8827ae0 100644 --- a/samples/client/petstore/powershell-experimental/Test1.ps1 +++ b/samples/client/petstore/powershell-experimental/Test1.ps1 @@ -29,33 +29,36 @@ try { #Write-Host $pet $Result = Add-PSPet -Pet $pet Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ" - $result = Get-PSPetById -petId $Id -Verbose #-testHeader "testing only" -testQuery "testing something here" + $Result2 = Get-PSPetById -petId ($Id + 10) -Verbose -WithHttpInfo #-testHeader "testing only" -testQuery "testing something here" + Write-Host $Result2.GetType() } catch { - Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json)) - Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) + #Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json)) + #Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) } +Write-Host "Before exit $($Result2.GetType())" + #$result | Write-Host #$result | Select-Object -Property "photoUrls" | ConvertTo-Json | Write-Host #Write-Host "result =" + $result.photoUrls -$pet2 = Initialize-PSPet -Id 20129 -Name '2foo' -Category ( - Initialize-PSCategory -Id 20129 -Name '2bar' -) -PhotoUrls @( - 'http://example.com/2foo', - 'http://example.com/2bar' -) -Tags ( - Initialize-PSTag -Id 3 -Name 'baz' -) -Status Available - -#Write-Host $pet -$Result = Add-PSPet -Pet $pet2 - -$Result = Find-PSPetsByTags 'baz' -Write-Host $Result.GetType().Name -Write-Host $Result +#$pet2 = Initialize-PSPet -Id 20129 -Name '2foo' -Category ( +# Initialize-PSCategory -Id 20129 -Name '2bar' +#) -PhotoUrls @( +# 'http://example.com/2foo', +# 'http://example.com/2bar' +#) -Tags ( +# Initialize-PSTag -Id 3 -Name 'baz' +#) -Status Available +# +##Write-Host $pet +#$Result = Add-PSPet -Pet $pet2 +# +#$Result = Find-PSPetsByTags 'baz' +#Write-Host $Result.GetType().Name +#Write-Host $Result #$Result = Invoke-PetApiUpdatePetWithForm -petId $Id -Name "PowerShell Update" -Status "Pending" diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Category.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Category.ps1 index 0229faf745a5..d1d49b9c1043 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Category.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Category.ps1 @@ -32,6 +32,7 @@ function Initialize-PSCategory { [System.Nullable[Int64]] ${Id}, [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] + [ValidatePattern("^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")] [String] ${Name} ) diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Order.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Order.ps1 index 01712b11284e..fd102068e30c 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Order.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Order.ps1 @@ -53,6 +53,7 @@ function Initialize-PSOrder { [System.Nullable[System.DateTime]] ${ShipDate}, [Parameter(Position = 4, ValueFromPipelineByPropertyName = $true)] + [ValidateSet("placed", "approved", "delivered")] [String] ${Status}, [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)] diff --git a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Pet.ps1 b/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Pet.ps1 index 801e97cdef06..47f41cff7761 100644 --- a/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Pet.ps1 +++ b/samples/client/petstore/powershell-experimental/src/PSPetstore/Model/Pet.ps1 @@ -46,16 +46,17 @@ function Initialize-PSPet { [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)] [PSCustomObject] ${Category}, - [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] + [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)] [String] ${Name}, - [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] + [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true)] [String[]] ${PhotoUrls}, [Parameter(Position = 4, ValueFromPipelineByPropertyName = $true)] [PSCustomObject[]] ${Tags}, [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)] + [ValidateSet("available", "pending", "sold")] [String] ${Status} ) @@ -64,6 +65,14 @@ function Initialize-PSPet { 'Creating PSCustomObject: PSPetstore => PSPet' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug + if (!$Name) { + throw "invalid value for 'Name', 'Name' cannot be null." + } + + if (!$PhotoUrls) { + throw "invalid value for 'PhotoUrls', 'PhotoUrls' cannot be null." + } + $PSO = [PSCustomObject]@{ "id" = ${Id} "category" = ${Category}