[PS] check if JSON properties is defined (#6419)

* check if json properties not defined

* add new files
This commit is contained in:
William Cheng 2020-05-25 21:06:59 +08:00 committed by GitHub
parent c000eaef73
commit f4897ea4a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 105 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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."
}

View File

@ -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 {

View File

@ -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 {