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:
parent
c000eaef73
commit
f4897ea4a4
@ -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
|
||||
|
33
samples/client/petstore/powershell/.openapi-generator/FILES
Normal file
33
samples/client/petstore/powershell/.openapi-generator/FILES
Normal 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
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user