1
1
package io .swagger .codegen .languages ;
2
2
3
- import io .swagger .codegen .*;
3
+ import io .swagger .codegen .CliOption ;
4
+ import io .swagger .codegen .CodegenConfig ;
5
+ import io .swagger .codegen .CodegenConstants ;
6
+ import io .swagger .codegen .CodegenModel ;
7
+ import io .swagger .codegen .CodegenProperty ;
8
+ import io .swagger .codegen .CodegenType ;
9
+ import io .swagger .codegen .DefaultCodegen ;
10
+ import io .swagger .codegen .SupportingFile ;
11
+
4
12
import io .swagger .models .Model ;
5
13
import io .swagger .models .ModelImpl ;
6
- import io .swagger .models .Operation ;
7
- import io .swagger .models .Swagger ;
8
14
import io .swagger .models .properties .ArrayProperty ;
9
15
import io .swagger .models .properties .MapProperty ;
10
16
import io .swagger .models .properties .Property ;
@@ -35,15 +41,15 @@ public class Swift5Codegen extends DefaultCodegen implements CodegenConfig {
35
41
public static final String SWIFT_USE_API_NAMESPACE = "swiftUseApiNamespace" ;
36
42
public static final String DEFAULT_POD_AUTHORS = "Swagger Codegen" ;
37
43
public static final String LENIENT_TYPE_CAST = "lenientTypeCast" ;
38
- protected static final String LIBRARY_PROMISE_KIT = "PromiseKit" ;
39
- protected static final String LIBRARY_RX_SWIFT = "RxSwift" ;
40
- protected static final String [] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT , LIBRARY_RX_SWIFT };
44
+ private static final String LIBRARY_PROMISE_KIT = "PromiseKit" ;
45
+ private static final String LIBRARY_RX_SWIFT = "RxSwift" ;
46
+ private static final String [] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT , LIBRARY_RX_SWIFT };
41
47
protected String projectName = "SwaggerClient" ;
42
- protected boolean unwrapRequired ;
43
- protected boolean objcCompatible = false ;
44
- protected boolean lenientTypeCast = false ;
48
+ private boolean unwrapRequired ;
49
+ private boolean objcCompatible = false ;
50
+ private boolean lenientTypeCast = false ;
45
51
protected boolean swiftUseApiNamespace ;
46
- protected String [] responseAs = new String [0 ];
52
+ private String [] responseAs = new String [0 ];
47
53
protected String sourceFolder = "Classes" + File .separator + "Swaggers" ;
48
54
49
55
@ Override
@@ -454,8 +460,7 @@ public String toDefaultValue(Property prop) {
454
460
public String toInstantiationType (Property prop ) {
455
461
if (prop instanceof MapProperty ) {
456
462
MapProperty ap = (MapProperty ) prop ;
457
- String inner = getSwaggerType (ap .getAdditionalProperties ());
458
- return inner ;
463
+ return getSwaggerType (ap .getAdditionalProperties ());
459
464
} else if (prop instanceof ArrayProperty ) {
460
465
ArrayProperty ap = (ArrayProperty ) prop ;
461
466
String inner = getSwaggerType (ap .getItems ());
@@ -555,7 +560,7 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
555
560
final CodegenModel parentCodegenModel = super .fromModel (codegenModel .parent ,
556
561
parentModel ,
557
562
allDefinitions );
558
- codegenModel = Swift5Codegen .reconcileProperties (codegenModel , parentCodegenModel );
563
+ Swift5Codegen .reconcileProperties (codegenModel , parentCodegenModel );
559
564
560
565
// get the next parent
561
566
parentSchema = parentCodegenModel .parentSchema ;
@@ -631,7 +636,7 @@ public String toEnumVarName(String name, String datatype) {
631
636
}
632
637
633
638
// Camelize only when we have a structure defined below
634
- Boolean camelized = false ;
639
+ boolean camelized = false ;
635
640
if (name .matches ("[A-Z][a-z0-9]+[a-zA-Z0-9]*" )) {
636
641
name = camelize (name , true );
637
642
camelized = true ;
@@ -661,7 +666,7 @@ public String toEnumVarName(String name, String datatype) {
661
666
662
667
char [] separators = {'-' , '_' , ' ' , ':' , '(' , ')' };
663
668
return camelize (WordUtils .capitalizeFully (StringUtils .lowerCase (name ), separators )
664
- .replaceAll ("[-_ :\\ ( \\ )]" , "" ),
669
+ .replaceAll ("[-_ :( )]" , "" ),
665
670
true );
666
671
}
667
672
@@ -761,8 +766,8 @@ public String escapeUnsafeCharacters(String input) {
761
766
return input .replace ("*/" , "*_/" ).replace ("/*" , "/_*" );
762
767
}
763
768
764
- private static CodegenModel reconcileProperties (CodegenModel codegenModel ,
765
- CodegenModel parentCodegenModel ) {
769
+ private static void reconcileProperties (CodegenModel codegenModel ,
770
+ CodegenModel parentCodegenModel ) {
766
771
// To support inheritance in this generator, we will analyze
767
772
// the parent and child models, look for properties that match, and remove
768
773
// them from the child models and leave them in the parent.
@@ -772,7 +777,7 @@ private static CodegenModel reconcileProperties(CodegenModel codegenModel,
772
777
// Get the properties for the parent and child models
773
778
final List <CodegenProperty > parentModelCodegenProperties = parentCodegenModel .vars ;
774
779
List <CodegenProperty > codegenProperties = codegenModel .vars ;
775
- codegenModel .allVars = new ArrayList <CodegenProperty >(codegenProperties );
780
+ codegenModel .allVars = new ArrayList <>(codegenProperties );
776
781
codegenModel .parentVars = parentCodegenModel .allVars ;
777
782
778
783
// Iterate over all of the parent model properties
@@ -784,7 +789,7 @@ private static CodegenModel reconcileProperties(CodegenModel codegenModel,
784
789
Iterator <CodegenProperty > iterator = codegenProperties .iterator ();
785
790
while (iterator .hasNext ()) {
786
791
CodegenProperty codegenProperty = iterator .next ();
787
- if (codegenProperty .baseName == parentModelCodegenProperty .baseName ) {
792
+ if (codegenProperty .baseName . equals ( parentModelCodegenProperty .baseName ) ) {
788
793
// We found a property in the child class that is
789
794
// a duplicate of the one in the parent, so remove it.
790
795
iterator .remove ();
@@ -799,12 +804,9 @@ private static CodegenModel reconcileProperties(CodegenModel codegenModel,
799
804
int numVars = codegenProperties .size ();
800
805
for (CodegenProperty codegenProperty : codegenProperties ) {
801
806
count += 1 ;
802
- codegenProperty .hasMore = ( count < numVars ) ? true : false ;
807
+ codegenProperty .hasMore = count < numVars ;
803
808
}
804
809
codegenModel .vars = codegenProperties ;
805
810
}
806
-
807
-
808
- return codegenModel ;
809
811
}
810
812
}
0 commit comments