@@ -350,6 +350,30 @@ public int compare(String o1, String o2) {
350
350
models .put ("classname" , config .toModelName (name ));
351
351
models .putAll (config .additionalProperties ());
352
352
allProcessedModels .put (name , models );
353
+
354
+ final List <Object > modelList = (List <Object >) models .get ("models" );
355
+
356
+ if (modelList == null || modelList .isEmpty ()) {
357
+ continue ;
358
+ }
359
+
360
+ for (Object object : modelList ) {
361
+ Map <String , Object > modelMap = (Map <String , Object >) object ;
362
+ CodegenModel codegenModel = null ;
363
+ if (modelMap .containsKey ("oneOf-model" )) {
364
+ codegenModel = (CodegenModel ) modelMap .get ("oneOf-model" );
365
+ }
366
+ if (modelMap .containsKey ("anyOf-model" )) {
367
+ codegenModel = (CodegenModel ) modelMap .get ("anyOf-model" );
368
+ }
369
+ if (codegenModel != null ) {
370
+ models = processModel (codegenModel , config , schemas );
371
+ models .put ("classname" , config .toModelName (codegenModel .name ));
372
+ models .putAll (config .additionalProperties ());
373
+ allProcessedModels .put (codegenModel .name , models );
374
+ break ;
375
+ }
376
+ }
353
377
} catch (Exception e ) {
354
378
throw new RuntimeException ("Could not process model '" + name + "'" + ".Please make sure that your schema is correct!" , e );
355
379
}
@@ -965,6 +989,14 @@ private Map<String, Object> processModels(CodegenConfig config, Map<String, Sche
965
989
Map <String , Object > mo = new HashMap <>();
966
990
mo .put ("model" , cm );
967
991
mo .put ("importPath" , config .toModelImport (cm .classname ));
992
+ if (cm .vendorExtensions .containsKey ("oneOf-model" )) {
993
+ CodegenModel oneOfModel = (CodegenModel ) cm .vendorExtensions .get ("oneOf-model" );
994
+ mo .put ("oneOf-model" , oneOfModel );
995
+ }
996
+ if (cm .vendorExtensions .containsKey ("anyOf-model" )) {
997
+ CodegenModel anyOfModel = (CodegenModel ) cm .vendorExtensions .get ("anyOf-model" );
998
+ mo .put ("anyOf-model" , anyOfModel );
999
+ }
968
1000
models .add (mo );
969
1001
970
1002
allImports .addAll (cm .imports );
@@ -996,6 +1028,50 @@ private Map<String, Object> processModels(CodegenConfig config, Map<String, Sche
996
1028
return objs ;
997
1029
}
998
1030
1031
+ private Map <String , Object > processModel (CodegenModel codegenModel , CodegenConfig config , Map <String , Schema > allDefinitions ) {
1032
+ Map <String , Object > objs = new HashMap <>();
1033
+ objs .put ("package" , config .modelPackage ());
1034
+ List <Object > models = new ArrayList <>();
1035
+
1036
+ if (codegenModel .vendorExtensions .containsKey ("x-is-composed-model" )) {
1037
+ objs .put ("x-is-composed-model" , codegenModel .vendorExtensions .get ("x-is-composed-model" ));
1038
+ }
1039
+
1040
+ Map <String , Object > modelObject = new HashMap <>();
1041
+ modelObject .put ("model" , codegenModel );
1042
+ modelObject .put ("importPath" , config .toModelImport (codegenModel .classname ));
1043
+
1044
+ Set <String > allImports = new LinkedHashSet <>();
1045
+ allImports .addAll (codegenModel .imports );
1046
+ models .add (modelObject );
1047
+
1048
+ objs .put ("models" , models );
1049
+ Set <String > importSet = new TreeSet <>();
1050
+ for (String nextImport : allImports ) {
1051
+ String mapping = config .importMapping ().get (nextImport );
1052
+ if (mapping == null ) {
1053
+ mapping = config .toModelImport (nextImport );
1054
+ }
1055
+ if (mapping != null && !config .defaultIncludes ().contains (mapping )) {
1056
+ importSet .add (mapping );
1057
+ }
1058
+ // add instantiation types
1059
+ mapping = config .instantiationTypes ().get (nextImport );
1060
+ if (mapping != null && !config .defaultIncludes ().contains (mapping )) {
1061
+ importSet .add (mapping );
1062
+ }
1063
+ }
1064
+ List <Map <String , String >> imports = new ArrayList <>();
1065
+ for (String s : importSet ) {
1066
+ Map <String , String > item = new HashMap <>();
1067
+ item .put ("import" , s );
1068
+ imports .add (item );
1069
+ }
1070
+ objs .put ("imports" , imports );
1071
+ config .postProcessModels (objs );
1072
+ return objs ;
1073
+ }
1074
+
999
1075
private Map <String , SecurityScheme > getAuthMethods (List <SecurityRequirement > securities , Map <String , SecurityScheme > securitySchemes ) {
1000
1076
if (securities == null || (securitySchemes == null || securitySchemes .isEmpty ())) {
1001
1077
return null ;
0 commit comments