fix(swift3): multi-level inheritance support

Supports multi-level inheritance to avoid having the variables from
the parents of level > 2

This commit also fixes the comparison of the variables when skipping
the variables in the children classes by only comparing their names
(in some cases some parent variables were present in children classes)

Signed-off-by: Vincent Giersch <vincent@giersch.fr>
This commit is contained in:
Vincent Giersch
2016-11-16 18:49:16 +01:00
parent 88227e08e3
commit bd06a629c6
5 changed files with 142 additions and 134 deletions

View File

@@ -427,10 +427,18 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
if(codegenModel.description != null) {
codegenModel.imports.add("ApiModel");
}
if (allDefinitions != null && codegenModel.parentSchema != null) {
final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
if (allDefinitions != null) {
String parentSchema = codegenModel.parentSchema;
// multilevel inheritance: reconcile properties of all the parents
while (parentSchema != null) {
final Model parentModel = allDefinitions.get(parentSchema);
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel, allDefinitions);
codegenModel = Swift3Codegen.reconcileProperties(codegenModel, parentCodegenModel);
// get the next parent
parentSchema = parentCodegenModel.parentSchema;
}
}
return codegenModel;
@@ -582,7 +590,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
Iterator<CodegenProperty> iterator = codegenProperties.iterator();
while (iterator.hasNext()) {
CodegenProperty codegenProperty = iterator.next();
if (codegenProperty.equals(parentModelCodegenProperty)) {
if (codegenProperty.baseName == parentModelCodegenProperty.baseName) {
// We found a property in the child class that is
// a duplicate of the one in the parent, so remove it.
iterator.remove();