@@ -70,6 +70,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
70
70
public static final String USE_BACKTICK_ESCAPES = "useBacktickEscapes" ;
71
71
public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES = "generateModelAdditionalProperties" ;
72
72
public static final String HASHABLE_MODELS = "hashableModels" ;
73
+ public static final String IDENTIFIABLE_MODELS = "identifiableModels" ;
73
74
public static final String USE_JSON_ENCODABLE = "useJsonEncodable" ;
74
75
public static final String MAP_FILE_BINARY_TO_DATA = "mapFileBinaryToData" ;
75
76
public static final String USE_CUSTOM_DATE_WITHOUT_TIME = "useCustomDateWithoutTime" ;
@@ -95,6 +96,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
95
96
@ Setter protected boolean useBacktickEscapes = false ;
96
97
@ Setter protected boolean generateModelAdditionalProperties = true ;
97
98
@ Setter protected boolean hashableModels = true ;
99
+ @ Setter protected boolean identifiableModels = true ;
98
100
@ Setter protected boolean useJsonEncodable = true ;
99
101
@ Getter @ Setter
100
102
protected boolean mapFileBinaryToData = false ;
@@ -303,6 +305,10 @@ public Swift5ClientCodegen() {
303
305
"Make hashable models (default: true)" )
304
306
.defaultValue (Boolean .TRUE .toString ()));
305
307
308
+ cliOptions .add (new CliOption (IDENTIFIABLE_MODELS ,
309
+ "Make models conform to Identifiable when an id is present (default: true)" )
310
+ .defaultValue (Boolean .TRUE .toString ()));
311
+
306
312
cliOptions .add (new CliOption (USE_JSON_ENCODABLE ,
307
313
"Make models conform to JSONEncodable protocol (default: true)" )
308
314
.defaultValue (Boolean .TRUE .toString ()));
@@ -507,6 +513,11 @@ public void processOpts() {
507
513
}
508
514
additionalProperties .put (HASHABLE_MODELS , hashableModels );
509
515
516
+ if (additionalProperties .containsKey (IDENTIFIABLE_MODELS )) {
517
+ setIdentifiableModels (convertPropertyToBooleanAndWriteBack (IDENTIFIABLE_MODELS ));
518
+ }
519
+ additionalProperties .put (IDENTIFIABLE_MODELS , identifiableModels );
520
+
510
521
if (additionalProperties .containsKey (USE_JSON_ENCODABLE )) {
511
522
setUseJsonEncodable (convertPropertyToBooleanAndWriteBack (USE_JSON_ENCODABLE ));
512
523
}
@@ -940,6 +951,15 @@ public CodegenModel fromModel(String name, Schema model) {
940
951
if (hashableModels ) {
941
952
codegenModel .vendorExtensions .put ("x-swift-hashable" , true );
942
953
}
954
+ if (identifiableModels && !codegenModel .vendorExtensions .containsKey ("x-swift-identifiable" )) {
955
+ for (CodegenProperty cp : codegenModel .getVars ()) {
956
+ if (!cp .getBaseName ().equals ("id" )) continue ;
957
+ if (cp .isString || cp .isUuid || cp .isInteger || cp .isLong ) {
958
+ codegenModel .vendorExtensions .put ("x-swift-identifiable" , true );
959
+ break ;
960
+ }
961
+ }
962
+ }
943
963
return codegenModel ;
944
964
}
945
965
0 commit comments