@@ -70,6 +70,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
7070 public static final String USE_BACKTICK_ESCAPES = "useBacktickEscapes" ;
7171 public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES = "generateModelAdditionalProperties" ;
7272 public static final String HASHABLE_MODELS = "hashableModels" ;
73+ public static final String USE_JSON_ENCODABLE = "useJsonEncodable" ;
7374 public static final String MAP_FILE_BINARY_TO_DATA = "mapFileBinaryToData" ;
7475 protected static final String LIBRARY_ALAMOFIRE = "alamofire" ;
7576 protected static final String LIBRARY_URLSESSION = "urlsession" ;
@@ -93,6 +94,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
9394 protected boolean useBacktickEscapes = false ;
9495 protected boolean generateModelAdditionalProperties = true ;
9596 protected boolean hashableModels = true ;
97+ protected boolean useJsonEncodable = true ;
9698 protected boolean mapFileBinaryToData = false ;
9799 protected String [] responseAs = new String [0 ];
98100 protected String sourceFolder = swiftPackagePath ;
@@ -299,6 +301,10 @@ public Swift5ClientCodegen() {
299301 "Make hashable models (default: true)" )
300302 .defaultValue (Boolean .TRUE .toString ()));
301303
304+ cliOptions .add (new CliOption (USE_JSON_ENCODABLE ,
305+ "Make models conform to JSONEncodable protocol (default: true)" )
306+ .defaultValue (Boolean .TRUE .toString ()));
307+
302308 cliOptions .add (new CliOption (MAP_FILE_BINARY_TO_DATA ,
303309 "[WARNING] This option will be removed and enabled by default in the future once we've enhanced the code to work with `Data` in all the different situations. Map File and Binary to Data (default: false)" )
304310 .defaultValue (Boolean .FALSE .toString ()));
@@ -497,6 +503,11 @@ public void processOpts() {
497503 }
498504 additionalProperties .put (HASHABLE_MODELS , hashableModels );
499505
506+ if (additionalProperties .containsKey (USE_JSON_ENCODABLE )) {
507+ setUseJsonEncodable (convertPropertyToBooleanAndWriteBack (USE_JSON_ENCODABLE ));
508+ }
509+ additionalProperties .put (USE_JSON_ENCODABLE , useJsonEncodable );
510+
500511 if (additionalProperties .containsKey (MAP_FILE_BINARY_TO_DATA )) {
501512 setMapFileBinaryToData (convertPropertyToBooleanAndWriteBack (MAP_FILE_BINARY_TO_DATA ));
502513 }
@@ -953,6 +964,10 @@ public void setHashableModels(boolean hashableModels) {
953964 this .hashableModels = hashableModels ;
954965 }
955966
967+ public void setUseJsonEncodable (boolean useJsonEncodable ) {
968+ this .useJsonEncodable = useJsonEncodable ;
969+ }
970+
956971 @ Override
957972 public String toEnumValue (String value , String datatype ) {
958973 // for string, array of string
@@ -995,7 +1010,7 @@ public String toEnumVarName(String name, String datatype) {
9951010 if (getSymbolName (name ) != null ) {
9961011 return camelize (WordUtils .capitalizeFully (getSymbolName (name ).toUpperCase (Locale .ROOT )), true );
9971012 }
998-
1013+
9991014 // Camelize only when we have a structure defined below
10001015 Boolean camelized = false ;
10011016 if (name .matches ("[A-Z][a-z0-9]+[a-zA-Z0-9]*" )) {
0 commit comments