35
35
import java .util .List ;
36
36
import java .util .ListIterator ;
37
37
import java .util .Map ;
38
+ import java .util .Objects ;
38
39
import java .util .regex .Pattern ;
39
40
40
41
import static io .swagger .codegen .v3 .CodegenConstants .HAS_ENUMS_EXT_NAME ;
@@ -1182,7 +1183,12 @@ private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, Code
1182
1183
while (iterator .hasNext ()) {
1183
1184
CodegenProperty codegenProperty = iterator .next ();
1184
1185
isEnum = getBooleanValue (codegenProperty , IS_ENUM_EXT_NAME );
1185
- if (isEnum && codegenProperty .equals (parentModelCodegenPropery )) {
1186
+ // we don't check for the full set of properties as they could be overridden
1187
+ // e.g. in the child; if we used codegenProperty.equals, the result in this
1188
+ // case would be `false` resulting on 2 different enums created on parent and
1189
+ // child classes, used in same method. This means that the child class will use
1190
+ // the enum defined in the parent, loosing any overridden property
1191
+ if (isEnum && isSameEnum (codegenProperty , parentModelCodegenPropery )) {
1186
1192
// We found an enum in the child class that is
1187
1193
// a duplicate of the one in the parent, so remove it.
1188
1194
iterator .remove ();
@@ -1199,11 +1205,48 @@ private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, Code
1199
1205
count += 1 ;
1200
1206
codegenProperty .getVendorExtensions ().put (CodegenConstants .HAS_MORE_EXT_NAME , (count < numVars ) ? true : false );
1201
1207
}
1208
+
1209
+ if (!codegenProperties .isEmpty ()) {
1210
+ codegenModel .getVendorExtensions ().put (CodegenConstants .HAS_VARS_EXT_NAME , true );
1211
+ codegenModel .getVendorExtensions ().put (CodegenConstants .HAS_ENUMS_EXT_NAME , false );
1212
+ } else {
1213
+ codegenModel .emptyVars = true ;
1214
+ codegenModel .getVendorExtensions ().put (CodegenConstants .HAS_VARS_EXT_NAME , false );
1215
+ codegenModel .getVendorExtensions ().put (CodegenConstants .HAS_ENUMS_EXT_NAME , false );
1216
+ }
1217
+
1218
+
1202
1219
codegenModel .vars = codegenProperties ;
1203
1220
}
1204
1221
return codegenModel ;
1222
+
1223
+
1205
1224
}
1206
1225
1226
+ protected static boolean isSameEnum (CodegenProperty actual , CodegenProperty other ) {
1227
+ if (actual == null && other == null ) {
1228
+ return true ;
1229
+ }
1230
+ if ((actual .name == null ) ? (other .name != null ) : !actual .name .equals (other .name )) {
1231
+ return false ;
1232
+ }
1233
+ if ((actual .baseName == null ) ? (other .baseName != null ) : !actual .baseName .equals (other .baseName )) {
1234
+ return false ;
1235
+ }
1236
+ if ((actual .datatype == null ) ? (other .datatype != null ) : !actual .datatype .equals (other .datatype )) {
1237
+ return false ;
1238
+ }
1239
+ if ((actual .datatypeWithEnum == null ) ? (other .datatypeWithEnum != null ) : !actual .datatypeWithEnum .equals (other .datatypeWithEnum )) {
1240
+ return false ;
1241
+ }
1242
+ if ((actual .baseType == null ) ? (other .baseType != null ) : !actual .baseType .equals (other .baseType )) {
1243
+ return false ;
1244
+ }
1245
+ if (!Objects .equals (actual .enumName , other .enumName )) {
1246
+ return false ;
1247
+ }
1248
+ return true ;
1249
+ }
1207
1250
private static String sanitizePackageName (String packageName ) {
1208
1251
packageName = packageName .trim (); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
1209
1252
packageName = packageName .replaceAll ("[^a-zA-Z0-9_\\ .]" , "_" );
0 commit comments