forked from loafle/openapi-generator-original
add discriminator support to anyOf powershell client (#6512)
This commit is contained in:
parent
4c3eb0d973
commit
0fbbbe8a95
@ -38,6 +38,35 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#discriminator}}
|
||||
{{#mappedModels}}
|
||||
{{#-first}}
|
||||
$JsonData = ConvertFrom-Json -InputObject $Json
|
||||
{{/-first}}
|
||||
# check if the discriminator value is '{{{mappingName}}}'
|
||||
if ($JsonData.PSobject.Properties["{{{propertyBaseName}}}"].value == "{{{mappingName}}}") {
|
||||
# try to match {{{modelName}}} defined in the anyOf schemas
|
||||
try {
|
||||
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
|
||||
|
||||
foreach($property in $matchInstance.PsObject.Properties) {
|
||||
if ($null -ne $property.Value) {
|
||||
$matchType = "{{{modelName}}}"
|
||||
return [PSCustomObject]@{
|
||||
"ActualType" = ${matchType}
|
||||
"ActualInstance" = ${matchInstance}
|
||||
"anyOfSchemas" = @({{#anyOf}}"{{{.}}}"{{^-last}}, {{/-last}}{{/anyOf}})
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
# fail to match the schema defined in anyOf with the discriminator lookup, proceed to the next one
|
||||
Write-Debug "Failed to match '{{{modelName}}}' defined in anyOf ({{{apiNamePrefix}}}{{{classname}}}) using the discriminator lookup ({{{mappingName}}}). Proceeding with the typical anyOf type matching."
|
||||
}
|
||||
}
|
||||
|
||||
{{/mappedModels}}
|
||||
{{/discriminator}}
|
||||
{{#anyOf}}
|
||||
if ($match -ne 0) { # no match yet
|
||||
# try to match {{{.}}} defined in the anyOf schemas
|
||||
|
Loading…
x
Reference in New Issue
Block a user