@@ -350,6 +350,24 @@ 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
+ if (modelMap .containsKey ("oneOf-model" )) {
363
+ CodegenModel oneOfModel = (CodegenModel ) modelMap .get ("oneOf-model" );
364
+ models = processModel (oneOfModel , config , schemas );
365
+ models .put ("classname" , config .toModelName (oneOfModel .name ));
366
+ models .putAll (config .additionalProperties ());
367
+ allProcessedModels .put (oneOfModel .name , models );
368
+ break ;
369
+ }
370
+ }
353
371
} catch (Exception e ) {
354
372
throw new RuntimeException ("Could not process model '" + name + "'" + ".Please make sure that your schema is correct!" , e );
355
373
}
@@ -952,6 +970,10 @@ private Map<String, Object> processModels(CodegenConfig config, Map<String, Sche
952
970
Map <String , Object > mo = new HashMap <>();
953
971
mo .put ("model" , cm );
954
972
mo .put ("importPath" , config .toModelImport (cm .classname ));
973
+ if (cm .vendorExtensions .containsKey ("oneOf-model" )) {
974
+ CodegenModel oneOfModel = (CodegenModel ) cm .vendorExtensions .get ("oneOf-model" );
975
+ mo .put ("oneOf-model" , oneOfModel );
976
+ }
955
977
models .add (mo );
956
978
957
979
allImports .addAll (cm .imports );
@@ -983,6 +1005,46 @@ private Map<String, Object> processModels(CodegenConfig config, Map<String, Sche
983
1005
return objs ;
984
1006
}
985
1007
1008
+ private Map <String , Object > processModel (CodegenModel codegenModel , CodegenConfig config , Map <String , Schema > allDefinitions ) {
1009
+ Map <String , Object > objs = new HashMap <>();
1010
+ objs .put ("package" , config .modelPackage ());
1011
+ List <Object > models = new ArrayList <>();
1012
+
1013
+ Map <String , Object > modelObject = new HashMap <>();
1014
+ modelObject .put ("model" , codegenModel );
1015
+ modelObject .put ("importPath" , config .toModelImport (codegenModel .classname ));
1016
+
1017
+ Set <String > allImports = new LinkedHashSet <>();
1018
+ allImports .addAll (codegenModel .imports );
1019
+ models .add (modelObject );
1020
+
1021
+ objs .put ("models" , models );
1022
+ Set <String > importSet = new TreeSet <>();
1023
+ for (String nextImport : allImports ) {
1024
+ String mapping = config .importMapping ().get (nextImport );
1025
+ if (mapping == null ) {
1026
+ mapping = config .toModelImport (nextImport );
1027
+ }
1028
+ if (mapping != null && !config .defaultIncludes ().contains (mapping )) {
1029
+ importSet .add (mapping );
1030
+ }
1031
+ // add instantiation types
1032
+ mapping = config .instantiationTypes ().get (nextImport );
1033
+ if (mapping != null && !config .defaultIncludes ().contains (mapping )) {
1034
+ importSet .add (mapping );
1035
+ }
1036
+ }
1037
+ List <Map <String , String >> imports = new ArrayList <>();
1038
+ for (String s : importSet ) {
1039
+ Map <String , String > item = new HashMap <>();
1040
+ item .put ("import" , s );
1041
+ imports .add (item );
1042
+ }
1043
+ objs .put ("imports" , imports );
1044
+ config .postProcessModels (objs );
1045
+ return objs ;
1046
+ }
1047
+
986
1048
private Map <String , SecurityScheme > getAuthMethods (List <SecurityRequirement > securities , Map <String , SecurityScheme > securitySchemes ) {
987
1049
if (securities == null || (securitySchemes == null || securitySchemes .isEmpty ())) {
988
1050
return null ;
0 commit comments