Skip to content

Commit

Permalink
Merge pull request #1184 from swagger-api/issue-1183
Browse files Browse the repository at this point in the history
set discriminator property name for all schemas
  • Loading branch information
HugoMario authored Sep 5, 2023
2 parents 985321a + f18244e commit 6ead997
Showing 1 changed file with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,9 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
codegenModel.getVendorExtensions().put(CodegenConstants.IS_ALIAS_EXT_NAME, typeAliases.containsKey(name));

codegenModel.discriminator = schema.getDiscriminator();
if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
}

if (schema.getXml() != null) {
codegenModel.xmlPrefix = schema.getXml().getPrefix();
Expand Down Expand Up @@ -1404,11 +1407,6 @@ else if (schema instanceof ComposedSchema) {
final List<Schema> allOf = composed.getAllOf();
// interfaces (intermediate models)
if (allOf != null && !allOf.isEmpty()) {

if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
}

for (int i = 0; i < allOf.size(); i++) {
if (i == 0 && !copyFistAllOfProperties) {
continue;
Expand All @@ -1435,16 +1433,6 @@ else if (schema instanceof ComposedSchema) {
}
}

final List<Schema> oneOf = composed.getOneOf();
if (oneOf != null && !oneOf.isEmpty()) {
if (schema.getDiscriminator() != null) {
codegenModel.discriminator = schema.getDiscriminator();
if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
}
}
}

if (parent != null) {
codegenModel.parentSchema = parentName;
codegenModel.parent = typeMapping.containsKey(parentName) ? typeMapping.get(parentName): toModelName(parentName);
Expand Down

0 comments on commit 6ead997

Please sign in to comment.