Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,27 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
if ("null<String, SystemCollectionsHashtable>".equals(model.parent)) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
$JsonData = ConvertFrom-Json -InputObject $Json
{{/-first}}
# 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 {
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
$JsonData = ConvertFrom-Json -InputObject $Json
{{/-first}}
# 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 {
$matchInstance = ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{modelName}}} $Json
Expand Down
11 changes: 0 additions & 11 deletions samples/client/petstore/powershell/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,3 @@ src/PSPetstore/Private/PSApiClient.ps1
src/PSPetstore/Private/PSHttpSignatureAuth.ps1
src/PSPetstore/Private/PSRSAEncryptionProvider.cs
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