forked from loafle/openapi-generator-original
add additional properties support to powershell client generator (#6528)
This commit is contained in:
parent
a6bf956df5
commit
5cf4ee1de8
@ -922,6 +922,10 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
model.anyOf.remove("ModelNull");
|
model.anyOf.remove("ModelNull");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add vendor extension for additonalProperties: true
|
||||||
|
if ("null<String, SystemCollectionsHashtable>".equals(model.parent)) {
|
||||||
|
model.vendorExtensions.put("x-additional-properties", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
|
@ -129,13 +129,24 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
|||||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||||
|
|
||||||
$JsonParameters = ConvertFrom-Json -InputObject $Json
|
$JsonParameters = ConvertFrom-Json -InputObject $Json
|
||||||
|
{{#vendorExtensions.x-additional-properties}}
|
||||||
|
${{{apiNamePrefix}}}{{{classname}}}AdditionalProperties = @{}
|
||||||
|
{{/vendorExtensions.x-additional-properties}}
|
||||||
|
|
||||||
# check if Json contains properties not defined in {{{apiNamePrefix}}}{{{classname}}}
|
# check if Json contains properties not defined in {{{apiNamePrefix}}}{{{classname}}}
|
||||||
$AllProperties = ({{#allVars}}"{{{baseName}}}"{{^-last}}, {{/-last}}{{/allVars}})
|
$AllProperties = ({{#allVars}}"{{{baseName}}}"{{^-last}}, {{/-last}}{{/allVars}})
|
||||||
foreach ($name in $JsonParameters.PsObject.Properties.Name) {
|
foreach ($name in $JsonParameters.PsObject.Properties.Name) {
|
||||||
|
{{^vendorExtensions.x-additional-properties}}
|
||||||
if (!($AllProperties.Contains($name))) {
|
if (!($AllProperties.Contains($name))) {
|
||||||
throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
|
throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
|
||||||
}
|
}
|
||||||
|
{{/vendorExtensions.x-additional-properties}}
|
||||||
|
{{#vendorExtensions.x-additional-properties}}
|
||||||
|
# store undefined properties in additionalProperties
|
||||||
|
if (!($AllProperties.Contains($name))) {
|
||||||
|
${{{apiNamePrefix}}}{{{classname}}}AdditionalProperties[$name] = $JsonParameters.PSobject.Properties[$name].value
|
||||||
|
}
|
||||||
|
{{/vendorExtensions.x-additional-properties}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#requiredVars}}
|
{{#requiredVars}}
|
||||||
@ -166,6 +177,9 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
|||||||
"<<baseName>>" = ${<<name>>}
|
"<<baseName>>" = ${<<name>>}
|
||||||
<</allVars>>
|
<</allVars>>
|
||||||
<<={{ }}=>>
|
<<={{ }}=>>
|
||||||
|
{{#vendorExtensions.x-additional-properties}}
|
||||||
|
"AdditionalProperties" = ${{{apiNamePrefix}}}{{{classname}}}AdditionalProperties
|
||||||
|
{{/vendorExtensions.x-additional-properties}}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $PSO
|
return $PSO
|
||||||
|
@ -699,6 +699,7 @@ components:
|
|||||||
xml:
|
xml:
|
||||||
name: User
|
name: User
|
||||||
Tag:
|
Tag:
|
||||||
|
additionalProperties: true
|
||||||
title: Pet Tag
|
title: Pet Tag
|
||||||
description: A tag for a pet
|
description: A tag for a pet
|
||||||
type: object
|
type: object
|
||||||
|
@ -77,12 +77,14 @@ function ConvertFrom-PSJsonToTag {
|
|||||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||||
|
|
||||||
$JsonParameters = ConvertFrom-Json -InputObject $Json
|
$JsonParameters = ConvertFrom-Json -InputObject $Json
|
||||||
|
$PSTagAdditionalProperties = @{}
|
||||||
|
|
||||||
# check if Json contains properties not defined in PSTag
|
# check if Json contains properties not defined in PSTag
|
||||||
$AllProperties = ("id", "name")
|
$AllProperties = ("id", "name")
|
||||||
foreach ($name in $JsonParameters.PsObject.Properties.Name) {
|
foreach ($name in $JsonParameters.PsObject.Properties.Name) {
|
||||||
|
# store undefined properties in additionalProperties
|
||||||
if (!($AllProperties.Contains($name))) {
|
if (!($AllProperties.Contains($name))) {
|
||||||
throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
|
$PSTagAdditionalProperties[$name] = $JsonParameters.PSobject.Properties[$name].value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +103,7 @@ function ConvertFrom-PSJsonToTag {
|
|||||||
$PSO = [PSCustomObject]@{
|
$PSO = [PSCustomObject]@{
|
||||||
"id" = ${Id}
|
"id" = ${Id}
|
||||||
"name" = ${Name}
|
"name" = ${Name}
|
||||||
|
"AdditionalProperties" = $PSTagAdditionalProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
return $PSO
|
return $PSO
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# Generated by: OpenAPI Generator Team
|
# Generated by: OpenAPI Generator Team
|
||||||
#
|
#
|
||||||
# Generated on: 5/19/20
|
# Generated on: 6/3/20
|
||||||
#
|
#
|
||||||
|
|
||||||
@{
|
@{
|
||||||
@ -87,7 +87,8 @@ FunctionsToExport = 'Add-PSPet', 'Remove-Pet', 'Find-PSPetsByStatus', 'Find-PSPe
|
|||||||
'Set-PSConfiguration', 'Set-PSConfigurationApiKey',
|
'Set-PSConfiguration', 'Set-PSConfigurationApiKey',
|
||||||
'Set-PSConfigurationApiKeyPrefix',
|
'Set-PSConfigurationApiKeyPrefix',
|
||||||
'Set-PSConfigurationDefaultHeader', 'Get-PSHostSetting',
|
'Set-PSConfigurationDefaultHeader', 'Get-PSHostSetting',
|
||||||
'Get-PSUrlFromHostSetting'
|
'Get-PSUrlFromHostSetting', 'Set-PSConfigurationHttpSigning',
|
||||||
|
'Get-PSConfigurationHttpSigning'
|
||||||
|
|
||||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||||
CmdletsToExport = @()
|
CmdletsToExport = @()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user