forked from loafle/openapi-generator-original
[PS] automatically derive discriminator mapping for oneOf/anyOf (#6542)
* infer mapping based on oneOf/anyOf schemas * update files
This commit is contained in:
parent
0f627e70fb
commit
176c439a6d
@ -926,6 +926,27 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
if ("null<String, SystemCollectionsHashtable>".equals(model.parent)) {
|
if ("null<String, SystemCollectionsHashtable>".equals(model.parent)) {
|
||||||
model.vendorExtensions.put("x-additional-properties", true);
|
model.vendorExtensions.put("x-additional-properties", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// automatically create discriminator mapping for oneOf/anyOf if not present
|
||||||
|
if (((model.oneOf != null && !model.oneOf.isEmpty()) || (model.anyOf != null && !model.anyOf.isEmpty())) &&
|
||||||
|
model.discriminator != null && model.discriminator.getMapping() == null) {
|
||||||
|
// create mappedModels
|
||||||
|
Set<String> schemas = new HashSet<>();
|
||||||
|
if (model.oneOf != null && !model.oneOf.isEmpty()) {
|
||||||
|
schemas = model.oneOf;
|
||||||
|
} else if (model.anyOf != null && !model.anyOf.isEmpty()) {
|
||||||
|
schemas = model.anyOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<CodegenDiscriminator.MappedModel> mappedModels = new HashSet<>();
|
||||||
|
|
||||||
|
for (String s: schemas) {
|
||||||
|
mappedModels.add(new CodegenDiscriminator.MappedModel(s, s));
|
||||||
|
}
|
||||||
|
|
||||||
|
model.discriminator.setMappedModels(mappedModels);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
|
@ -44,7 +44,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
|||||||
$JsonData = ConvertFrom-Json -InputObject $Json
|
$JsonData = ConvertFrom-Json -InputObject $Json
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
# check if the discriminator value is '{{{mappingName}}}'
|
# check if the discriminator value is '{{{mappingName}}}'
|
||||||
if ($JsonData.PSobject.Properties["{{{propertyBaseName}}}"].value == "{{{mappingName}}}") {
|
if ($JsonData.PSobject.Properties["{{{propertyBaseName}}}"].value -eq "{{{mappingName}}}") {
|
||||||
# try to match {{{modelName}}} defined in the anyOf schemas
|
# try to match {{{modelName}}} defined in the anyOf schemas
|
||||||
try {
|
try {
|
||||||
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
|
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
|
||||||
|
@ -45,7 +45,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
|||||||
$JsonData = ConvertFrom-Json -InputObject $Json
|
$JsonData = ConvertFrom-Json -InputObject $Json
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
# check if the discriminator value is '{{{mappingName}}}'
|
# check if the discriminator value is '{{{mappingName}}}'
|
||||||
if ($JsonData.PSobject.Properties["{{{propertyBaseName}}}"].value == "{{{mappingName}}}") {
|
if ($JsonData.PSobject.Properties["{{{propertyBaseName}}}"].value -eq "{{{mappingName}}}") {
|
||||||
# try to match {{{modelName}}} defined in the oneOf schemas
|
# try to match {{{modelName}}} defined in the oneOf schemas
|
||||||
try {
|
try {
|
||||||
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
|
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
|
||||||
|
@ -31,14 +31,3 @@ src/PSPetstore/Private/PSApiClient.ps1
|
|||||||
src/PSPetstore/Private/PSHttpSignatureAuth.ps1
|
src/PSPetstore/Private/PSHttpSignatureAuth.ps1
|
||||||
src/PSPetstore/Private/PSRSAEncryptionProvider.cs
|
src/PSPetstore/Private/PSRSAEncryptionProvider.cs
|
||||||
src/PSPetstore/en-US/about_PSPetstore.help.txt
|
src/PSPetstore/en-US/about_PSPetstore.help.txt
|
||||||
tests/Api/PSPetApi.Tests.ps1
|
|
||||||
tests/Api/PSStoreApi.Tests.ps1
|
|
||||||
tests/Api/PSUserApi.Tests.ps1
|
|
||||||
tests/Model/ApiResponse.Tests.ps1
|
|
||||||
tests/Model/Category.Tests.ps1
|
|
||||||
tests/Model/InlineObject.Tests.ps1
|
|
||||||
tests/Model/InlineObject1.Tests.ps1
|
|
||||||
tests/Model/Order.Tests.ps1
|
|
||||||
tests/Model/Pet.Tests.ps1
|
|
||||||
tests/Model/Tag.Tests.ps1
|
|
||||||
tests/Model/User.Tests.ps1
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user