diff --git a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache index 6929c038a11..6e7eadef78d 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache @@ -130,6 +130,14 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in {{{apiNamePrefix}}}{{{classname}}} + $AllProperties = ({{#allVars}}"{{{baseName}}}"{{^-last}}, {{/-last}}{{/allVars}}) + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + {{#requiredVars}} {{#-first}} If ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") { # empty json diff --git a/samples/client/petstore/powershell/.openapi-generator/FILES b/samples/client/petstore/powershell/.openapi-generator/FILES new file mode 100644 index 00000000000..4708e0914a5 --- /dev/null +++ b/samples/client/petstore/powershell/.openapi-generator/FILES @@ -0,0 +1,33 @@ +Build.ps1 +README.md +appveyor.yml +docs/ApiResponse.md +docs/Category.md +docs/InlineObject.md +docs/InlineObject1.md +docs/Order.md +docs/PSPetApi.md +docs/PSStoreApi.md +docs/PSUserApi.md +docs/Pet.md +docs/Tag.md +docs/User.md +src/PSPetstore/Api/PSPetApi.ps1 +src/PSPetstore/Api/PSStoreApi.ps1 +src/PSPetstore/Api/PSUserApi.ps1 +src/PSPetstore/Client/PSConfiguration.ps1 +src/PSPetstore/Model/ApiResponse.ps1 +src/PSPetstore/Model/Category.ps1 +src/PSPetstore/Model/InlineObject.ps1 +src/PSPetstore/Model/InlineObject1.ps1 +src/PSPetstore/Model/Order.ps1 +src/PSPetstore/Model/Pet.ps1 +src/PSPetstore/Model/Tag.ps1 +src/PSPetstore/Model/User.ps1 +src/PSPetstore/PSPetstore.psm1 +src/PSPetstore/Private/Get-CommonParameters.ps1 +src/PSPetstore/Private/Out-DebugParameter.ps1 +src/PSPetstore/Private/PSApiClient.ps1 +src/PSPetstore/Private/PSHttpSignatureAuth.ps1 +src/PSPetstore/Private/PSRSAEncryptionProvider.cs +src/PSPetstore/en-US/about_PSPetstore.help.txt diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/ApiResponse.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/ApiResponse.ps1 index 098775df7ee..1cc58e9d5dc 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/ApiResponse.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/ApiResponse.ps1 @@ -85,6 +85,14 @@ function ConvertFrom-PSJsonToApiResponse { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSApiResponse + $AllProperties = ("code", "type", "message") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "code"))) { #optional property not found $Code = $null } else { diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/Category.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Category.ps1 index cb85b6c2e73..5d5e93da8e5 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/Category.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/Category.ps1 @@ -79,6 +79,14 @@ function ConvertFrom-PSJsonToCategory { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSCategory + $AllProperties = ("id", "name") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found $Id = $null } else { diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject.ps1 index 97ca828980d..fbfde854a24 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject.ps1 @@ -78,6 +78,14 @@ function ConvertFrom-PSJsonToInlineObject { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSInlineObject + $AllProperties = ("name", "status") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "name"))) { #optional property not found $Name = $null } else { diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject1.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject1.ps1 index 98d26313ae5..cfd49e06365 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject1.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/InlineObject1.ps1 @@ -78,6 +78,14 @@ function ConvertFrom-PSJsonToInlineObject1 { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSInlineObject1 + $AllProperties = ("additionalMetadata", "file") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "additionalMetadata"))) { #optional property not found $AdditionalMetadata = $null } else { diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1 index 29f88643cea..d74819356ad 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1 @@ -107,6 +107,14 @@ function ConvertFrom-PSJsonToOrder { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSOrder + $AllProperties = ("id", "petId", "quantity", "shipDate", "status", "complete") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found $Id = $null } else { diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 index df59392c973..d9c53786d54 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 @@ -115,6 +115,14 @@ function ConvertFrom-PSJsonToPet { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSPet + $AllProperties = ("id", "category", "name", "photoUrls", "tags", "status") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + If ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") { # empty json throw "Error! Empty JSON cannot be serialized due to the required property `name` missing." } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/Tag.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Tag.ps1 index 30ec0ab8045..0f0044ef35c 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/Tag.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/Tag.ps1 @@ -78,6 +78,14 @@ function ConvertFrom-PSJsonToTag { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSTag + $AllProperties = ("id", "name") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found $Id = $null } else { diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/User.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/User.ps1 index c3a6568d3d8..493322216a2 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/User.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/User.ps1 @@ -121,6 +121,14 @@ function ConvertFrom-PSJsonToUser { $JsonParameters = ConvertFrom-Json -InputObject $Json + # check if Json contains properties not defined in PSUser + $AllProperties = ("id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus") + foreach ($name in $JsonParameters.PsObject.Properties.Name) { + if (!($AllProperties.Contains($name))) { + throw "Error! JSON key '$name' not found in the properties: $($AllProperties)" + } + } + if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found $Id = $null } else {