@@ -2012,13 +2012,23 @@ public ModelsMap postProcessModels(ModelsMap objs) {
20122012 listIterator .add (newImportMap );
20132013 }
20142014 }
2015+ // make sure the x-implements is always a List and always at least empty
2016+ for (ModelMap mo : objs .getModels ()) {
2017+ CodegenModel cm = mo .getModel ();
2018+ if (cm .getVendorExtensions ().containsKey (X_IMPLEMENTS )) {
2019+ List <String > xImplements = getObjectAsStringList (cm .getVendorExtensions ().get (X_IMPLEMENTS ));
2020+ cm .getVendorExtensions ().replace (X_IMPLEMENTS , xImplements );
2021+ } else {
2022+ cm .getVendorExtensions ().put (X_IMPLEMENTS , new ArrayList <String >());
2023+ }
2024+ }
20152025
20162026 // skip interfaces predefined in open api spec in x-implements via additional property xImplementsSkip
20172027 if (!this .xImplementsSkip .isEmpty ()) {
20182028 for (ModelMap mo : objs .getModels ()) {
20192029 CodegenModel cm = mo .getModel ();
2020- if (cm .getVendorExtensions ().containsKey (X_IMPLEMENTS )) {
2021- List <String > xImplementsInModelOriginal = ( List < String >) cm .getVendorExtensions ().get (X_IMPLEMENTS );
2030+ if (! getObjectAsStringList ( cm .getVendorExtensions ().get (X_IMPLEMENTS )). isEmpty ( )) {
2031+ List <String > xImplementsInModelOriginal = getObjectAsStringList ( cm .getVendorExtensions ().get (X_IMPLEMENTS ) );
20222032 List <String > xImplementsInModelSkipped = xImplementsInModelOriginal
20232033 .stream ()
20242034 .filter (o -> this .xImplementsSkip .contains (o ))
@@ -2040,8 +2050,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
20402050 CodegenModel cm = mo .getModel ();
20412051 if (this .schemaImplements .containsKey (cm .getSchemaName ())) {
20422052 LOGGER .info ("Adding interface(s) {} configured via config option '{}' to model {}" , this .schemaImplements .get (cm .getSchemaName ()), SCHEMA_IMPLEMENTS , cm .classname );
2043- cm .getVendorExtensions ().putIfAbsent (X_IMPLEMENTS , new ArrayList <String >());
2044- List <String > xImplementsInModel = (List <String >) cm .getVendorExtensions ().get (X_IMPLEMENTS );
2053+ List <String > xImplementsInModel = getObjectAsStringList (cm .getVendorExtensions ().get (X_IMPLEMENTS ));
20452054 List <String > schemaImplements = this .schemaImplements .get (cm .getSchemaName ());
20462055 List <String > combinedSchemaImplements = Stream .concat (xImplementsInModel .stream (), schemaImplements .stream ())
20472056 .collect (Collectors .toList ());
@@ -2051,12 +2060,15 @@ public ModelsMap postProcessModels(ModelsMap objs) {
20512060 }
20522061 }
20532062
2054- // add x-implements for serializable to all models
2055- for (ModelMap mo : objs .getModels ()) {
2056- CodegenModel cm = mo .getModel ();
2057- if (this .serializableModel ) {
2058- cm .getVendorExtensions ().putIfAbsent (X_IMPLEMENTS , new ArrayList <String >());
2059- ((ArrayList <String >) cm .getVendorExtensions ().get (X_IMPLEMENTS )).add ("Serializable" );
2063+ // add Serializable to x-implements to all models if configured
2064+ if (this .serializableModel ) {
2065+ for (ModelMap mo : objs .getModels ()) {
2066+ CodegenModel cm = mo .getModel ();
2067+ List <String > xImplements = new ArrayList <>(getObjectAsStringList (cm .getVendorExtensions ().get (X_IMPLEMENTS )));
2068+ if (!xImplements .contains ("Serializable" )) {
2069+ xImplements .add ("Serializable" );
2070+ }
2071+ cm .getVendorExtensions ().replace (X_IMPLEMENTS , xImplements );
20602072 }
20612073 }
20622074
0 commit comments