forked from loafle/openapi-generator-original
Ensure model.allParents
always includes model.parent
. (#5738)
`allParents` is used by generators with multiple inheritance, e.g typescript and perl
This commit is contained in:
parent
e47739dda5
commit
c5472be422
@ -1236,7 +1236,6 @@ public class ModelUtils {
|
||||
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) {
|
||||
@ -1255,7 +1254,6 @@ public class ModelUtils {
|
||||
}
|
||||
} else {
|
||||
// not a parent since discriminator.propertyName is not set
|
||||
refedWithoutDiscriminator.add(parentName);
|
||||
}
|
||||
} else {
|
||||
// not a ref, doing nothing
|
||||
@ -1263,10 +1261,11 @@ public class ModelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -604,6 +604,18 @@ public class DefaultCodegenTest {
|
||||
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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user