Skip to content

Commit 6089123

Browse files
authored
Merge pull request #10262 from swagger-api/issue-8148
Issue 8148
2 parents 022bc89 + dbbb446 commit 6089123

File tree

9 files changed

+101
-69
lines changed

9 files changed

+101
-69
lines changed

modules/swagger-codegen/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
<artifactId>maven-compiler-plugin</artifactId>
7575
<version>3.5.1</version>
7676
<configuration>
77-
<source>1.7</source>
78-
<target>1.7</target>
77+
<source>1.8</source>
78+
<target>1.8</target>
7979
</configuration>
8080
</plugin>
8181
<plugin>

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -190,43 +190,48 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
190190
allModels.put(modelName, cm);
191191
}
192192
}
193-
// Fix up all parent and interface CodegenModel references.
194-
for (CodegenModel cm : allModels.values()) {
195-
if (cm.parent != null) {
196-
cm.parentModel = allModels.get(cm.parent);
197-
}
198-
if (cm.interfaces != null && !cm.interfaces.isEmpty()) {
199-
cm.interfaceModels = new ArrayList<CodegenModel>(cm.interfaces.size());
200-
for (String intf : cm.interfaces) {
201-
CodegenModel intfModel = allModels.get(intf);
202-
if (intfModel != null) {
203-
cm.interfaceModels.add(intfModel);
204-
}
205-
}
206-
}
207-
}
208-
// Let parent know about all its children
193+
209194
for (String name : allModels.keySet()) {
210-
CodegenModel cm = allModels.get(name);
211-
CodegenModel parent = allModels.get(cm.parent);
212-
// if a discriminator exists on the parent, don't add this child to the inheritance hierarchy
213-
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
214-
while (parent != null) {
215-
if (parent.children == null) {
216-
parent.children = new ArrayList<CodegenModel>();
217-
}
218-
parent.children.add(cm);
219-
if (parent.discriminator == null) {
220-
parent = allModels.get(parent.parent);
221-
} else {
222-
parent = null;
223-
}
224-
}
195+
CodegenModel codegenModel = allModels.get(name);
196+
fixUpParentAndInterfaces(codegenModel, allModels);
225197
}
226198
}
227199
return objs;
228200
}
229201

202+
/**
203+
* Fix up all parent and interface CodegenModel references.
204+
* @param allModels
205+
*/
206+
protected void fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String, CodegenModel> allModels) {
207+
if (codegenModel.parent != null) {
208+
codegenModel.parentModel = allModels.get(codegenModel.parent);
209+
}
210+
if (codegenModel.interfaces != null && !codegenModel.interfaces.isEmpty()) {
211+
codegenModel.interfaceModels = new ArrayList<CodegenModel>(codegenModel.interfaces.size());
212+
for (String intf : codegenModel.interfaces) {
213+
CodegenModel intfModel = allModels.get(intf);
214+
if (intfModel != null) {
215+
codegenModel.interfaceModels.add(intfModel);
216+
}
217+
}
218+
}
219+
CodegenModel parent = codegenModel.parentModel;
220+
// if a discriminator exists on the parent, don't add this child to the inheritance hierarchy
221+
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
222+
while (parent != null) {
223+
if (parent.children == null) {
224+
parent.children = new ArrayList<CodegenModel>();
225+
}
226+
parent.children.add(codegenModel);
227+
if (parent.discriminator == null) {
228+
parent = allModels.get(parent.parent);
229+
} else {
230+
parent = null;
231+
}
232+
}
233+
}
234+
230235
// override with any special post-processing
231236
@SuppressWarnings("static-method")
232237
public Map<String, Object> postProcessModels(Map<String, Object> objs) {

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,33 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
938938
}
939939
}
940940

941+
@Override
942+
protected void fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String, CodegenModel> allModels) {
943+
super.fixUpParentAndInterfaces(codegenModel, allModels);
944+
if (codegenModel.vars == null || codegenModel.vars.isEmpty() || codegenModel.parentModel == null) {
945+
return;
946+
}
947+
CodegenModel parentModel = codegenModel.parentModel;
948+
949+
for (CodegenProperty codegenProperty : codegenModel.vars) {
950+
while (parentModel != null) {
951+
if (parentModel.vars == null || parentModel.vars.isEmpty()) {
952+
parentModel = parentModel.parentModel;
953+
continue;
954+
}
955+
boolean hasConflict = parentModel.vars.stream()
956+
.anyMatch(parentProperty -> parentProperty.name.equals(codegenProperty.name) && !parentProperty.datatype.equals(codegenProperty.datatype));
957+
if (hasConflict) {
958+
codegenProperty.name = toVarName(codegenModel.name + "_" + codegenProperty.name);
959+
codegenProperty.getter = toGetter(codegenProperty.name);
960+
codegenProperty.setter = toGetter(codegenProperty.name);
961+
break;
962+
}
963+
parentModel = parentModel.parentModel;
964+
}
965+
}
966+
}
967+
941968
@Override
942969
public void postProcessParameter(CodegenParameter parameter) { }
943970

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
</execution>
8484
</executions> -->
8585
<configuration>
86-
<compilerSource>1.7</compilerSource>
87-
<compilerCompliance>1.7</compilerCompliance>
88-
<compilerTargetPlatform>1.7</compilerTargetPlatform>
86+
<compilerSource>1.8</compilerSource>
87+
<compilerCompliance>1.8</compilerCompliance>
88+
<compilerTargetPlatform>1.8</compilerTargetPlatform>
8989
<lineEnding>LF</lineEnding>
9090
</configuration>
9191
</plugin>
@@ -159,8 +159,8 @@
159159
<artifactId>maven-compiler-plugin</artifactId>
160160
<version>3.6.1</version>
161161
<configuration>
162-
<source>1.7</source>
163-
<target>1.7</target>
162+
<source>1.8</source>
163+
<target>1.8</target>
164164
</configuration>
165165
</plugin>
166166
<plugin>
@@ -195,7 +195,7 @@
195195
<version>2.10.4</version>
196196
<configuration>
197197
<aggregate>true</aggregate>
198-
<source>1.7</source>
198+
<source>1.8</source>
199199
<encoding>UTF-8</encoding>
200200
<maxmemory>1g</maxmemory>
201201
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>

pom.xml.bash

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
</execution>
8484
</executions> -->
8585
<configuration>
86-
<compilerSource>1.7</compilerSource>
87-
<compilerCompliance>1.7</compilerCompliance>
88-
<compilerTargetPlatform>1.7</compilerTargetPlatform>
86+
<compilerSource>1.8</compilerSource>
87+
<compilerCompliance>1.8</compilerCompliance>
88+
<compilerTargetPlatform>1.8</compilerTargetPlatform>
8989
<lineEnding>LF</lineEnding>
9090
</configuration>
9191
</plugin>
@@ -159,8 +159,8 @@
159159
<artifactId>maven-compiler-plugin</artifactId>
160160
<version>3.6.1</version>
161161
<configuration>
162-
<source>1.7</source>
163-
<target>1.7</target>
162+
<source>1.8</source>
163+
<target>1.8</target>
164164
</configuration>
165165
</plugin>
166166
<plugin>
@@ -195,7 +195,7 @@
195195
<version>2.10.4</version>
196196
<configuration>
197197
<aggregate>true</aggregate>
198-
<source>1.7</source>
198+
<source>1.8</source>
199199
<encoding>UTF-8</encoding>
200200
<maxmemory>1g</maxmemory>
201201
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>

pom.xml.circleci

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
</execution>
8888
</executions> -->
8989
<configuration>
90-
<compilerSource>1.7</compilerSource>
91-
<compilerCompliance>1.7</compilerCompliance>
92-
<compilerTargetPlatform>1.7</compilerTargetPlatform>
90+
<compilerSource>1.8</compilerSource>
91+
<compilerCompliance>1.8</compilerCompliance>
92+
<compilerTargetPlatform>1.8</compilerTargetPlatform>
9393
<lineEnding>LF</lineEnding>
9494
</configuration>
9595
</plugin>
@@ -163,8 +163,8 @@
163163
<artifactId>maven-compiler-plugin</artifactId>
164164
<version>3.6.1</version>
165165
<configuration>
166-
<source>1.7</source>
167-
<target>1.7</target>
166+
<source>1.8</source>
167+
<target>1.8</target>
168168
</configuration>
169169
</plugin>
170170
<plugin>
@@ -199,7 +199,7 @@
199199
<version>2.10.4</version>
200200
<configuration>
201201
<aggregate>true</aggregate>
202-
<source>1.7</source>
202+
<source>1./</source>
203203
<encoding>UTF-8</encoding>
204204
<maxmemory>1g</maxmemory>
205205
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>

pom.xml.ios

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
</execution>
8484
</executions> -->
8585
<configuration>
86-
<compilerSource>1.7</compilerSource>
87-
<compilerCompliance>1.7</compilerCompliance>
88-
<compilerTargetPlatform>1.7</compilerTargetPlatform>
86+
<compilerSource>1.8</compilerSource>
87+
<compilerCompliance>1.8</compilerCompliance>
88+
<compilerTargetPlatform>1.8</compilerTargetPlatform>
8989
<lineEnding>LF</lineEnding>
9090
</configuration>
9191
</plugin>
@@ -159,8 +159,8 @@
159159
<artifactId>maven-compiler-plugin</artifactId>
160160
<version>3.6.1</version>
161161
<configuration>
162-
<source>1.7</source>
163-
<target>1.7</target>
162+
<source>1.8</source>
163+
<target>1.8</target>
164164
</configuration>
165165
</plugin>
166166
<plugin>
@@ -195,7 +195,7 @@
195195
<version>2.10.4</version>
196196
<configuration>
197197
<aggregate>true</aggregate>
198-
<source>1.7</source>
198+
<source>1.8</source>
199199
<encoding>UTF-8</encoding>
200200
<maxmemory>1g</maxmemory>
201201
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>

pom.xml.jenkins

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
</execution>
8484
</executions> -->
8585
<configuration>
86-
<compilerSource>1.7</compilerSource>
87-
<compilerCompliance>1.7</compilerCompliance>
88-
<compilerTargetPlatform>1.7</compilerTargetPlatform>
86+
<compilerSource>1.8</compilerSource>
87+
<compilerCompliance>1.8</compilerCompliance>
88+
<compilerTargetPlatform>1.8</compilerTargetPlatform>
8989
<lineEnding>LF</lineEnding>
9090
</configuration>
9191
</plugin>
@@ -159,8 +159,8 @@
159159
<artifactId>maven-compiler-plugin</artifactId>
160160
<version>3.6.1</version>
161161
<configuration>
162-
<source>1.7</source>
163-
<target>1.7</target>
162+
<source>1.8</source>
163+
<target>1.8</target>
164164
</configuration>
165165
</plugin>
166166
<plugin>
@@ -195,7 +195,7 @@
195195
<version>2.10.4</version>
196196
<configuration>
197197
<aggregate>true</aggregate>
198-
<source>1.7</source>
198+
<source>1.8</source>
199199
<encoding>UTF-8</encoding>
200200
<maxmemory>1g</maxmemory>
201201
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>

pom.xml.travis

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
</execution>
8484
</executions> -->
8585
<configuration>
86-
<compilerSource>1.7</compilerSource>
87-
<compilerCompliance>1.7</compilerCompliance>
88-
<compilerTargetPlatform>1.7</compilerTargetPlatform>
86+
<compilerSource>1.8</compilerSource>
87+
<compilerCompliance>1.8</compilerCompliance>
88+
<compilerTargetPlatform>1.8</compilerTargetPlatform>
8989
<lineEnding>LF</lineEnding>
9090
</configuration>
9191
</plugin>
@@ -159,8 +159,8 @@
159159
<artifactId>maven-compiler-plugin</artifactId>
160160
<version>3.6.1</version>
161161
<configuration>
162-
<source>1.7</source>
163-
<target>1.7</target>
162+
<source>1.8</source>
163+
<target>1.8</target>
164164
</configuration>
165165
</plugin>
166166
<plugin>
@@ -195,7 +195,7 @@
195195
<version>2.10.4</version>
196196
<configuration>
197197
<aggregate>true</aggregate>
198-
<source>1.7</source>
198+
<source>1.8</source>
199199
<encoding>UTF-8</encoding>
200200
<maxmemory>1g</maxmemory>
201201
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>

0 commit comments

Comments
 (0)