1
1
package io .swagger .codegen .languages ;
2
2
3
- import com .google .common .base .Predicate ;
4
- import com .google .common .collect .Iterators ;
5
- import com .google .common .collect .Lists ;
6
-
7
3
import io .swagger .codegen .CliOption ;
8
4
import io .swagger .codegen .CodegenConfig ;
9
5
import io .swagger .codegen .CodegenConstants ;
15
11
16
12
import io .swagger .models .Model ;
17
13
import io .swagger .models .ModelImpl ;
18
- import io .swagger .models .Operation ;
19
- import io .swagger .models .Swagger ;
20
- import io .swagger .models .parameters .HeaderParameter ;
21
- import io .swagger .models .parameters .Parameter ;
22
14
import io .swagger .models .properties .ArrayProperty ;
23
15
import io .swagger .models .properties .MapProperty ;
24
16
import io .swagger .models .properties .Property ;
37
29
import java .util .Map ;
38
30
import java .util .regex .Matcher ;
39
31
import java .util .regex .Pattern ;
40
- import javax .annotation .Nullable ;
41
32
42
33
public class Swift5Codegen extends DefaultCodegen implements CodegenConfig {
43
34
public static final String PROJECT_NAME = "projectName" ;
@@ -57,15 +48,15 @@ public class Swift5Codegen extends DefaultCodegen implements CodegenConfig {
57
48
public static final String SWIFT_USE_API_NAMESPACE = "swiftUseApiNamespace" ;
58
49
public static final String DEFAULT_POD_AUTHORS = "Swagger Codegen" ;
59
50
public static final String LENIENT_TYPE_CAST = "lenientTypeCast" ;
60
- protected static final String LIBRARY_PROMISE_KIT = "PromiseKit" ;
61
- protected static final String LIBRARY_RX_SWIFT = "RxSwift" ;
62
- protected static final String [] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT , LIBRARY_RX_SWIFT };
51
+ private static final String LIBRARY_PROMISE_KIT = "PromiseKit" ;
52
+ private static final String LIBRARY_RX_SWIFT = "RxSwift" ;
53
+ private static final String [] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT , LIBRARY_RX_SWIFT };
63
54
protected String projectName = "SwaggerClient" ;
64
- protected boolean unwrapRequired ;
65
- protected boolean objcCompatible = false ;
66
- protected boolean lenientTypeCast = false ;
55
+ private boolean unwrapRequired ;
56
+ private boolean objcCompatible = false ;
57
+ private boolean lenientTypeCast = false ;
67
58
protected boolean swiftUseApiNamespace ;
68
- protected String [] responseAs = new String [0 ];
59
+ private String [] responseAs = new String [0 ];
69
60
protected String sourceFolder = "Classes" + File .separator + "Swaggers" ;
70
61
71
62
@ Override
@@ -476,8 +467,7 @@ public String toDefaultValue(Property prop) {
476
467
public String toInstantiationType (Property prop ) {
477
468
if (prop instanceof MapProperty ) {
478
469
MapProperty ap = (MapProperty ) prop ;
479
- String inner = getSwaggerType (ap .getAdditionalProperties ());
480
- return inner ;
470
+ return getSwaggerType (ap .getAdditionalProperties ());
481
471
} else if (prop instanceof ArrayProperty ) {
482
472
ArrayProperty ap = (ArrayProperty ) prop ;
483
473
String inner = getSwaggerType (ap .getItems ());
@@ -577,7 +567,7 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
577
567
final CodegenModel parentCodegenModel = super .fromModel (codegenModel .parent ,
578
568
parentModel ,
579
569
allDefinitions );
580
- codegenModel = Swift5Codegen .reconcileProperties (codegenModel , parentCodegenModel );
570
+ Swift5Codegen .reconcileProperties (codegenModel , parentCodegenModel );
581
571
582
572
// get the next parent
583
573
parentSchema = parentCodegenModel .parentSchema ;
@@ -642,7 +632,7 @@ public String toEnumVarName(String name, String datatype) {
642
632
}
643
633
644
634
// Camelize only when we have a structure defined below
645
- Boolean camelized = false ;
635
+ boolean camelized = false ;
646
636
if (name .matches ("[A-Z][a-z0-9]+[a-zA-Z0-9]*" )) {
647
637
name = camelize (name , true );
648
638
camelized = true ;
@@ -672,7 +662,7 @@ public String toEnumVarName(String name, String datatype) {
672
662
673
663
char [] separators = {'-' , '_' , ' ' , ':' , '(' , ')' };
674
664
return camelize (WordUtils .capitalizeFully (StringUtils .lowerCase (name ), separators )
675
- .replaceAll ("[-_ :\\ ( \\ )]" , "" ),
665
+ .replaceAll ("[-_ :( )]" , "" ),
676
666
true );
677
667
}
678
668
@@ -772,8 +762,8 @@ public String escapeUnsafeCharacters(String input) {
772
762
return input .replace ("*/" , "*_/" ).replace ("/*" , "/_*" );
773
763
}
774
764
775
- private static CodegenModel reconcileProperties (CodegenModel codegenModel ,
776
- CodegenModel parentCodegenModel ) {
765
+ private static void reconcileProperties (CodegenModel codegenModel ,
766
+ CodegenModel parentCodegenModel ) {
777
767
// To support inheritance in this generator, we will analyze
778
768
// the parent and child models, look for properties that match, and remove
779
769
// them from the child models and leave them in the parent.
@@ -783,7 +773,7 @@ private static CodegenModel reconcileProperties(CodegenModel codegenModel,
783
773
// Get the properties for the parent and child models
784
774
final List <CodegenProperty > parentModelCodegenProperties = parentCodegenModel .vars ;
785
775
List <CodegenProperty > codegenProperties = codegenModel .vars ;
786
- codegenModel .allVars = new ArrayList <CodegenProperty >(codegenProperties );
776
+ codegenModel .allVars = new ArrayList <>(codegenProperties );
787
777
codegenModel .parentVars = parentCodegenModel .allVars ;
788
778
789
779
// Iterate over all of the parent model properties
@@ -795,7 +785,7 @@ private static CodegenModel reconcileProperties(CodegenModel codegenModel,
795
785
Iterator <CodegenProperty > iterator = codegenProperties .iterator ();
796
786
while (iterator .hasNext ()) {
797
787
CodegenProperty codegenProperty = iterator .next ();
798
- if (codegenProperty .baseName == parentModelCodegenProperty .baseName ) {
788
+ if (codegenProperty .baseName . equals ( parentModelCodegenProperty .baseName ) ) {
799
789
// We found a property in the child class that is
800
790
// a duplicate of the one in the parent, so remove it.
801
791
iterator .remove ();
@@ -810,12 +800,9 @@ private static CodegenModel reconcileProperties(CodegenModel codegenModel,
810
800
int numVars = codegenProperties .size ();
811
801
for (CodegenProperty codegenProperty : codegenProperties ) {
812
802
count += 1 ;
813
- codegenProperty .hasMore = ( count < numVars ) ? true : false ;
803
+ codegenProperty .hasMore = count < numVars ;
814
804
}
815
805
codegenModel .vars = codegenProperties ;
816
806
}
817
-
818
-
819
- return codegenModel ;
820
807
}
821
808
}
0 commit comments