Skip to content

Commit 8c599eb

Browse files
authored
Add support for multiple inheritance (#1664)
* add all parent names * clean up supportsInheritance * fix npe * fix allVars, fix test cases * add more tests, remove comments * update docker m2 cache dir, add more tests, fix mandatory * update samples * regenerate js spec files * add logic to detect self reference * add isSelfReference flag to codegen property * add ruby tests for cat model * remove debugging info * fix JS allvars not have x-js-doctype * update samples * update js samples
1 parent 587bd56 commit 8c599eb

File tree

214 files changed

+829
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+829
-448
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public interface CodegenConfig {
171171

172172
void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations);
173173

174+
Map<String, Object> updateAllModels(Map<String, Object> objs);
175+
174176
Map<String, Object> postProcessAllModels(Map<String, Object> objs);
175177

176178
Map<String, Object> postProcessModels(Map<String, Object> objs);

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

+68-12
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import java.util.*;
2323

2424
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
25+
import org.apache.commons.lang3.builder.ToStringBuilder;
2526

2627
@JsonIgnoreProperties({"parentModel", "interfaceModels"})
2728
public class CodegenModel {
2829
public String parent, parentSchema;
2930
public List<String> interfaces;
31+
public List<String> allParents;
3032

3133
// References to parent and interface CodegenModels. Only set when code generator supports inheritance.
3234
public CodegenModel parentModel;
@@ -46,18 +48,18 @@ public class CodegenModel {
4648
public String arrayModelType;
4749
public boolean isAlias; // Is this effectively an alias of another simple type
4850
public boolean isString, isInteger;
49-
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
51+
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>(); // all properties (without parent's properties)
52+
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>(); // all properties (with parent's properties)
5053
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>(); // a list of required properties
5154
public List<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
5255
public List<CodegenProperty> readOnlyVars = new ArrayList<CodegenProperty>(); // a list of read-only properties
5356
public List<CodegenProperty> readWriteVars = new ArrayList<CodegenProperty>(); // a list of properties for read, write
54-
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>();
5557
public List<CodegenProperty> parentVars = new ArrayList<CodegenProperty>();
5658
public Map<String, Object> allowableValues;
5759

5860
// Sorted sets of required parameters.
59-
public Set<String> mandatory = new TreeSet<String>();
60-
public Set<String> allMandatory;
61+
public Set<String> mandatory = new TreeSet<String>(); // without parent's required properties
62+
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
6163

6264
public Set<String> imports = new TreeSet<String>();
6365
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel;
@@ -69,16 +71,59 @@ public class CodegenModel {
6971
//The type of the value from additional properties. Used in map like objects.
7072
public String additionalPropertiesType;
7173

72-
{
73-
// By default these are the same collections. Where the code generator supports inheritance, composed models
74-
// store the complete closure of owned and inherited properties in allVars and allMandatory.
75-
allVars = vars;
76-
allMandatory = mandatory;
77-
}
78-
7974
@Override
8075
public String toString() {
81-
return String.format(Locale.ROOT, "%s(%s)", name, classname);
76+
return new ToStringBuilder(this)
77+
.append("parent", parent)
78+
.append("parentSchema", parentSchema)
79+
.append("interfaces", interfaces)
80+
.append("parentModel", parentModel)
81+
.append("interfaceModels", interfaceModels)
82+
.append("children", children)
83+
.append("name", name)
84+
.append("classname", classname)
85+
.append("title", title)
86+
.append("description", description)
87+
.append("classVarName", classVarName)
88+
.append("modelJson", modelJson)
89+
.append("dataType", dataType)
90+
.append("xmlPrefix", xmlPrefix)
91+
.append("xmlNamespace", xmlNamespace)
92+
.append("xmlName", xmlName)
93+
.append("classFilename", classFilename)
94+
.append("unescapedDescription", unescapedDescription)
95+
.append("discriminator", discriminator)
96+
.append("defaultValue", defaultValue)
97+
.append("arrayModelType", arrayModelType)
98+
.append("isAlias", isAlias)
99+
.append("isString", isString)
100+
.append("isInteger", isInteger)
101+
.append("vars", vars)
102+
.append("requiredVars", requiredVars)
103+
.append("optionalVars", optionalVars)
104+
.append("readOnlyVars", readOnlyVars)
105+
.append("readWriteVars", readWriteVars)
106+
.append("allVars", allVars)
107+
.append("parentVars", parentVars)
108+
.append("allowableValues", allowableValues)
109+
.append("mandatory", mandatory)
110+
.append("allMandatory", allMandatory)
111+
.append("imports", imports)
112+
.append("hasVars", hasVars)
113+
.append("emptyVars", emptyVars)
114+
.append("hasMoreModels", hasMoreModels)
115+
.append("hasEnums", hasEnums)
116+
.append("isEnum", isEnum)
117+
.append("hasRequired", hasRequired)
118+
.append("hasOptional", hasOptional)
119+
.append("isArrayModel", isArrayModel)
120+
.append("hasChildren", hasChildren)
121+
.append("isMapModel", isMapModel)
122+
.append("hasOnlyReadOnly", hasOnlyReadOnly)
123+
.append("externalDocumentation", externalDocumentation)
124+
.append("vendorExtensions", vendorExtensions)
125+
.append("additionalPropertiesType", additionalPropertiesType)
126+
.toString();
82127
}
83128

84129
@Override
@@ -94,6 +139,8 @@ public boolean equals(Object o) {
94139
return false;
95140
if (interfaces != null ? !interfaces.equals(that.interfaces) : that.interfaces != null)
96141
return false;
142+
if (allParents != null ? !allParents.equals(that.allParents) : that.allParents != null)
143+
return false;
97144
if (parentModel != null ? !parentModel.equals(that.parentModel) : that.parentModel != null)
98145
return false;
99146
if (interfaceModels != null ? !interfaceModels.equals(that.interfaceModels) : that.interfaceModels != null)
@@ -169,6 +216,7 @@ public int hashCode() {
169216
int result = parent != null ? parent.hashCode() : 0;
170217
result = 31 * result + (parentSchema != null ? parentSchema.hashCode() : 0);
171218
result = 31 * result + (interfaces != null ? interfaces.hashCode() : 0);
219+
result = 31 * result + (allParents != null ? allParents.hashCode() : 0);
172220
result = 31 * result + (parentModel != null ? parentModel.hashCode() : 0);
173221
result = 31 * result + (interfaceModels != null ? interfaceModels.hashCode() : 0);
174222
result = 31 * result + (name != null ? name.hashCode() : 0);
@@ -226,10 +274,18 @@ public List<String> getInterfaces() {
226274
return interfaces;
227275
}
228276

277+
public List<String> getAllParents() {
278+
return allParents;
279+
}
280+
229281
public void setInterfaces(List<String> interfaces) {
230282
this.interfaces = interfaces;
231283
}
232284

285+
public void setAllParents(List<String> allParents) {
286+
this.allParents = allParents;
287+
}
288+
233289
public CodegenModel getParentModel() {
234290
return parentModel;
235291
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class CodegenProperty implements Cloneable {
6161
public boolean isReadOnly;
6262
public boolean isWriteOnly;
6363
public boolean isNullable;
64+
public boolean isSelfReference;
6465
public List<String> _enum;
6566
public Map<String, Object> allowableValues;
6667
public CodegenProperty items;
@@ -439,6 +440,7 @@ public int hashCode() {
439440
result = prime * result + ((isReadOnly ? 13 : 31));
440441
result = prime * result + ((isWriteOnly ? 13 : 31));
441442
result = prime * result + ((isNullable ? 13 : 31));
443+
result = prime * result + ((isSelfReference ? 13 : 31));
442444
result = prime * result + ((items == null) ? 0 : items.hashCode());
443445
result = prime * result + ((mostInnerItems == null) ? 0 : mostInnerItems.hashCode());
444446
result = prime * result + ((jsonSchema == null) ? 0 : jsonSchema.hashCode());
@@ -597,6 +599,9 @@ public boolean equals(Object obj) {
597599
if (this.isNullable != other.isNullable) {
598600
return false;
599601
}
602+
if (this.isSelfReference != other.isSelfReference ) {
603+
return false;
604+
}
600605
if (this._enum != other._enum && (this._enum == null || !this._enum.equals(other._enum))) {
601606
return false;
602607
}
@@ -790,6 +795,7 @@ public java.lang.String toString() {
790795
", isReadOnly=" + isReadOnly +
791796
", isWriteOnly=" + isWriteOnly +
792797
", isNullable=" + isNullable +
798+
", isSelfReference=" + isSelfReference +
793799
", _enum=" + _enum +
794800
", allowableValues=" + allowableValues +
795801
", items=" + items +

0 commit comments

Comments
 (0)