From fd2976b89c99c69698a73f78ad5f8705158dcadf Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 10 Jun 2020 11:27:53 +0800 Subject: [PATCH] use legacy discriminator mapping (#6604) --- .../languages/PowerShellClientCodegen.java | 23 +------------------ .../resources/powershell/model_oneof.mustache | 2 +- .../powershell/model_simple.mustache | 2 +- .../powershell/src/PSPetstore/Model/Pet.ps1 | 4 ++-- 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java index d3e519a9a7f..74a439c3d4c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java @@ -60,7 +60,6 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo */ public PowerShellClientCodegen() { super(); - modifyFeatureSet(features -> features .includeDocumentationFeatures(DocumentationFeature.Readme) .wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML)) @@ -546,6 +545,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo @Override public void processOpts() { + this.setLegacyDiscriminatorBehavior(false); super.processOpts(); if (StringUtils.isEmpty(System.getenv("POWERSHELL_POST_PROCESS_FILE"))) { @@ -926,27 +926,6 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo if ("null".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 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 mappedModels = new HashSet<>(); - - for (String s: schemas) { - mappedModels.add(new CodegenDiscriminator.MappedModel(s, s)); - } - - model.discriminator.setMappedModels(mappedModels); - - } } return objs; diff --git a/modules/openapi-generator/src/main/resources/powershell/model_oneof.mustache b/modules/openapi-generator/src/main/resources/powershell/model_oneof.mustache index e71d77814d2..39a1044c1f3 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_oneof.mustache @@ -65,7 +65,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} { Write-Debug "Failed to match '{{{modelName}}}' defined in oneOf ({{{apiNamePrefix}}}{{{classname}}}) using the discriminator lookup ({{{mappingName}}}). Proceeding with the typical oneOf type matching." } } - + {{/mappedModels}} {{/discriminator}} {{/useOneOfDiscriminatorLookup}} diff --git a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache index ab7098fe9f9..aab5d1fd291 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache @@ -157,7 +157,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} { {{/-first}} if (!([bool]($JsonParameters.PSobject.Properties.name -match "{{{baseName}}}"))) { - throw "Error! JSON cannot be serialized due to the required property `{{{baseName}}}` missing." + throw "Error! JSON cannot be serialized due to the required property `{{{baseName}}}` missing." } else { ${{name}} = $JsonParameters.PSobject.Properties["{{{baseName}}}"].value } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 index d9c53786d54..4af7e7ecc82 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/Pet.ps1 @@ -128,13 +128,13 @@ function ConvertFrom-PSJsonToPet { } if (!([bool]($JsonParameters.PSobject.Properties.name -match "name"))) { - throw "Error! JSON cannot be serialized due to the required property `name` missing." + throw "Error! JSON cannot be serialized due to the required property `name` missing." } else { $Name = $JsonParameters.PSobject.Properties["name"].value } if (!([bool]($JsonParameters.PSobject.Properties.name -match "photoUrls"))) { - throw "Error! JSON cannot be serialized due to the required property `photoUrls` missing." + throw "Error! JSON cannot be serialized due to the required property `photoUrls` missing." } else { $PhotoUrls = $JsonParameters.PSobject.Properties["photoUrls"].value }