Skip to content

Commit

Permalink
Merge pull request #620 from swagger-api/issue-617
Browse files Browse the repository at this point in the history
fixed allOf discriminator issue.
  • Loading branch information
HugoMario authored Mar 9, 2020
2 parents 81a9246 + fc53106 commit 1130576
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,6 @@ 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 (schema.getXml() != null) {
codegenModel.xmlPrefix = schema.getXml().getPrefix();
codegenModel.xmlNamespace = schema.getXml().getNamespace();
Expand Down Expand Up @@ -1342,6 +1340,14 @@ else if (schema instanceof ComposedSchema) {
final List<Schema> allOf = composed.getAllOf();
// interfaces (intermediate models)
if (allOf != null && !allOf.isEmpty()) {

if (schema.getDiscriminator() != null) {
codegenModel.discriminator = schema.getDiscriminator();
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void simpleModelTest() {
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 7);
Assert.assertEquals(cm.discriminator.getPropertyName(),"test");

final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "id");
Expand Down Expand Up @@ -119,8 +118,7 @@ private Schema getSimpleSchema() {
.addProperties("uuid", new UUIDSchema())
.addProperties("dateOfBirth", new DateSchema())
.addRequiredItem("id")
.addRequiredItem("name")
.discriminator(new Discriminator().propertyName("test"));
.addRequiredItem("name");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void simpleModelTest() {
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 7);
Assert.assertEquals(cm.discriminator.getPropertyName(),"test");

final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "id");
Expand Down Expand Up @@ -119,8 +118,7 @@ private Schema getSimpleSchema() {
.addProperties("uuid", new UUIDSchema())
.addProperties("dateOfBirth", new DateSchema())
.addRequiredItem("id")
.addRequiredItem("name")
.discriminator(new Discriminator().propertyName("test"));
.addRequiredItem("name");
}

}

0 comments on commit 1130576

Please sign in to comment.