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 @@ -1236,7 +1236,6 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
public static List<String> getAllParentsName(ComposedSchema composedSchema, Map<String, Schema> allSchemas, boolean includeAncestors) {
List<Schema> interfaces = getInterfaces(composedSchema);
List<String> names = new ArrayList<String>();
List<String> refedWithoutDiscriminator = new ArrayList<>();

if (interfaces != null && !interfaces.isEmpty()) {
for (Schema schema : interfaces) {
Expand All @@ -1255,18 +1254,18 @@ public static List<String> getAllParentsName(ComposedSchema composedSchema, Map<
}
} else {
// not a parent since discriminator.propertyName is not set
refedWithoutDiscriminator.add(parentName);
}
} else {
// not a ref, doing nothing
}
}
}

if (names.size() == 0 && refedWithoutDiscriminator.size() == 1) {
LOGGER.warn("[deprecated] inheritance without use of 'discriminator.propertyName' is deprecated " +
"and will be removed in a future release. Generating model for {}. Title: {}", composedSchema.getName(), composedSchema.getTitle());
return refedWithoutDiscriminator;
// ensure `allParents` always includes `parent`
// this is more robust than keeping logic in getParentName() and getAllParentsName() in sync
String parentName = getParentName(composedSchema, allSchemas);
if (parentName != null && !names.contains(parentName)) {
names.add(parentName);
}

return names;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ public void testAllOfRequired() {
Assert.assertEquals(getRequiredVars(childModel), Collections.singletonList("name"));
}

@Test
public void testAllOfSingleRefWithOwnPropsNoDiscriminator() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/composed-allof.yaml");
final DefaultCodegen codegen = new CodegenWithMultipleInheritance();

Schema schema = openAPI.getComponents().getSchemas().get("MessageEventCoreWithTimeListEntries");
codegen.setOpenAPI(openAPI);
CodegenModel model = codegen.fromModel("MessageEventCoreWithTimeListEntries", schema);
Assert.assertEquals(model.parent, "MessageEventCore");
Assert.assertEquals(model.allParents, Collections.singletonList("MessageEventCore"));
}

@Test
public void testAllOfSingleRefNoOwnProps() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/composed-allof.yaml");
Expand Down