forked from loafle/openapi-generator-original
use legacy discriminator mapping (#6604)
This commit is contained in:
parent
233087c5aa
commit
fd2976b89c
@ -60,7 +60,6 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
*/
|
*/
|
||||||
public PowerShellClientCodegen() {
|
public PowerShellClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
modifyFeatureSet(features -> features
|
modifyFeatureSet(features -> features
|
||||||
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||||
.wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML))
|
.wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML))
|
||||||
@ -546,6 +545,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processOpts() {
|
public void processOpts() {
|
||||||
|
this.setLegacyDiscriminatorBehavior(false);
|
||||||
super.processOpts();
|
super.processOpts();
|
||||||
|
|
||||||
if (StringUtils.isEmpty(System.getenv("POWERSHELL_POST_PROCESS_FILE"))) {
|
if (StringUtils.isEmpty(System.getenv("POWERSHELL_POST_PROCESS_FILE"))) {
|
||||||
@ -926,27 +926,6 @@ 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;
|
||||||
|
@ -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."
|
Write-Debug "Failed to match '{{{modelName}}}' defined in oneOf ({{{apiNamePrefix}}}{{{classname}}}) using the discriminator lookup ({{{mappingName}}}). Proceeding with the typical oneOf type matching."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/mappedModels}}
|
{{/mappedModels}}
|
||||||
{{/discriminator}}
|
{{/discriminator}}
|
||||||
{{/useOneOfDiscriminatorLookup}}
|
{{/useOneOfDiscriminatorLookup}}
|
||||||
|
@ -157,7 +157,7 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
|||||||
|
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
if (!([bool]($JsonParameters.PSobject.Properties.name -match "{{{baseName}}}"))) {
|
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 {
|
} else {
|
||||||
${{name}} = $JsonParameters.PSobject.Properties["{{{baseName}}}"].value
|
${{name}} = $JsonParameters.PSobject.Properties["{{{baseName}}}"].value
|
||||||
}
|
}
|
||||||
|
@ -128,13 +128,13 @@ function ConvertFrom-PSJsonToPet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!([bool]($JsonParameters.PSobject.Properties.name -match "name"))) {
|
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 {
|
} else {
|
||||||
$Name = $JsonParameters.PSobject.Properties["name"].value
|
$Name = $JsonParameters.PSobject.Properties["name"].value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!([bool]($JsonParameters.PSobject.Properties.name -match "photoUrls"))) {
|
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 {
|
} else {
|
||||||
$PhotoUrls = $JsonParameters.PSobject.Properties["photoUrls"].value
|
$PhotoUrls = $JsonParameters.PSobject.Properties["photoUrls"].value
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user