forked from loafle/openapi-generator-original
Compare commits
1 Commits
master
...
fix_allof_
Author | SHA1 | Date | |
---|---|---|---|
|
75f9335515 |
@ -1222,8 +1222,6 @@ public class ModelUtils {
|
|||||||
public static String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
public static String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||||
List<Schema> interfaces = getInterfaces(composedSchema);
|
List<Schema> interfaces = getInterfaces(composedSchema);
|
||||||
int nullSchemaChildrenCount = 0;
|
int nullSchemaChildrenCount = 0;
|
||||||
boolean hasAmbiguousParents = false;
|
|
||||||
List<String> refedWithoutDiscriminator = new ArrayList<>();
|
|
||||||
|
|
||||||
if (interfaces != null && !interfaces.isEmpty()) {
|
if (interfaces != null && !interfaces.isEmpty()) {
|
||||||
for (Schema schema : interfaces) {
|
for (Schema schema : interfaces) {
|
||||||
@ -1238,9 +1236,10 @@ public class ModelUtils {
|
|||||||
// discriminator.propertyName is used
|
// discriminator.propertyName is used
|
||||||
return parentName;
|
return parentName;
|
||||||
} else {
|
} else {
|
||||||
// not a parent since discriminator.propertyName is not set
|
// TOOD to be removed in 6.x release
|
||||||
hasAmbiguousParents = true;
|
LOGGER.warn("[deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated" +
|
||||||
refedWithoutDiscriminator.add(parentName);
|
" in the 5.x release. Composed schema name: {}. Title: {}",
|
||||||
|
composedSchema.getName(), composedSchema.getTitle());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not a ref, doing nothing, except counting the number of times the 'null' type
|
// not a ref, doing nothing, except counting the number of times the 'null' type
|
||||||
@ -1253,21 +1252,6 @@ public class ModelUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (refedWithoutDiscriminator.size() == 1 && nullSchemaChildrenCount == 1) {
|
|
||||||
// One schema is a $ref and the other is the 'null' type, so the parent is obvious.
|
|
||||||
// In this particular case there is no need to specify a discriminator.
|
|
||||||
hasAmbiguousParents = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parent name only makes sense when there is a single obvious parent
|
|
||||||
if (refedWithoutDiscriminator.size() == 1) {
|
|
||||||
if (hasAmbiguousParents) {
|
|
||||||
LOGGER.warn("[deprecated] inheritance without use of 'discriminator.propertyName' is deprecated " +
|
|
||||||
"and will be removed in a future release. Generating model for composed schema name: {}. Title: {}",
|
|
||||||
composedSchema.getName(), composedSchema.getTitle());
|
|
||||||
}
|
|
||||||
return refedWithoutDiscriminator.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -1372,9 +1372,9 @@ public class DefaultCodegenTest {
|
|||||||
Schema schema = openAPI.getComponents().getSchemas().get("NewMessageEventCoreNoOwnProps");
|
Schema schema = openAPI.getComponents().getSchemas().get("NewMessageEventCoreNoOwnProps");
|
||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
CodegenModel model = codegen.fromModel("NewMessageEventCoreNoOwnProps", schema);
|
CodegenModel model = codegen.fromModel("NewMessageEventCoreNoOwnProps", schema);
|
||||||
Assert.assertEquals(getNames(model.getVars()), Collections.emptyList());
|
Assert.assertEquals(getNames(model.getVars()), Arrays.asList("id","message"));
|
||||||
Assert.assertEquals(model.parent, "MessageEventCore");
|
Assert.assertNull(model.parent);
|
||||||
Assert.assertEquals(model.allParents, Collections.singletonList("MessageEventCore"));
|
Assert.assertNull(model.allParents);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CodegenWithMultipleInheritance extends DefaultCodegen {
|
class CodegenWithMultipleInheritance extends DefaultCodegen {
|
||||||
|
@ -25,6 +25,7 @@ import io.swagger.v3.oas.models.media.Discriminator;
|
|||||||
import io.swagger.v3.oas.models.media.ObjectSchema;
|
import io.swagger.v3.oas.models.media.ObjectSchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import io.swagger.v3.oas.models.media.StringSchema;
|
import io.swagger.v3.oas.models.media.StringSchema;
|
||||||
|
import java.util.Collections;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.CodegenModel;
|
import org.openapitools.codegen.CodegenModel;
|
||||||
import org.openapitools.codegen.CodegenProperty;
|
import org.openapitools.codegen.CodegenProperty;
|
||||||
@ -57,8 +58,8 @@ public class JavaInheritanceTest {
|
|||||||
|
|
||||||
Assert.assertEquals(cm.name, "sample");
|
Assert.assertEquals(cm.name, "sample");
|
||||||
Assert.assertEquals(cm.classname, "Sample");
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
Assert.assertEquals(cm.parent, "Base");
|
Assert.assertNull(cm.parent);
|
||||||
Assert.assertEquals(cm.imports, Sets.newHashSet("Base"));
|
Assert.assertEquals(cm.imports, Collections.emptySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "convert a composed model with discriminator")
|
@Test(description = "convert a composed model with discriminator")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user