forked from loafle/openapi-generator-original
[PS] check if JSON properties is defined (#6419)
* check if json properties not defined * add new files
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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."
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user