From c8f92630f154adf4c1fd9ae658fe499e1a1206c5 Mon Sep 17 00:00:00 2001 From: Michael Nahkies Date: Tue, 27 Aug 2019 21:40:22 +0100 Subject: [PATCH] [core] [regression] set parentName when a single possible parent exists Whilst the spec states that the 'allOf' relationship does not imply a hierarchy: > While composition offers model extensibility, it does not imply a hierarchy between the models. > To support polymorphism, the OpenAPI Specification adds the discriminator field. Unfortunately this does not make sense for many existing use cases, that were supported by older versions of the generator. Therefore, I've restored the older behavior, specifically in the case that only a single possible parent schema is present. I think a more complete solution would generate interfaces for the composed schemas, and mark the generated class as implementing these. fixes issue 2845, and fixes issue #3523 --- .../org/openapitools/codegen/utils/ModelUtils.java | 10 ++++++++++ .../openapitools/codegen/java/JavaInheritanceTest.java | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index ad991f679545..50c9250224bd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -896,6 +896,8 @@ public static List getInterfaces(ComposedSchema composed) { public static String getParentName(ComposedSchema composedSchema, Map allSchemas) { List interfaces = getInterfaces(composedSchema); + List refedParentNames = new ArrayList<>(); + if (interfaces != null && !interfaces.isEmpty()) { for (Schema schema : interfaces) { // get the actual schema @@ -911,6 +913,7 @@ public static String getParentName(ComposedSchema composedSchema, Map