@@ -59,9 +59,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
59
59
String supportedElixirVersion = "1.10" ;
60
60
List <String > extraApplications = Arrays .asList (":logger" );
61
61
List <String > deps = Arrays .asList (
62
- "{:tesla, \" ~> 1.4\" }" ,
63
- "{:poison, \" ~> 3.0\" }" ,
64
- "{:ex_doc, \" ~> 0.28\" , only: :dev, runtime: false}"
62
+ "{:tesla, \" ~> 1.7\" }" ,
63
+ "{:jason, \" ~> 1.4\" }" ,
64
+ "{:ex_doc, \" ~> 0.30\" , only: :dev, runtime: false}" ,
65
+ "{:dialyxir, \" ~> 1.3\" , only: [:dev, :test], runtime: false}"
65
66
);
66
67
67
68
public ElixirClientCodegen () {
@@ -194,7 +195,6 @@ public ElixirClientCodegen() {
194
195
"AnyType" ,
195
196
"Tuple" ,
196
197
"PID" ,
197
- "DateTime" ,
198
198
"map()" , // This is a workaround, since the DefaultCodeGen uses our elixir TypeSpec datetype to evaluate the primitive
199
199
"any()"
200
200
)
@@ -210,7 +210,7 @@ public ElixirClientCodegen() {
210
210
typeMapping .put ("string" , "String" );
211
211
typeMapping .put ("byte" , "Integer" );
212
212
typeMapping .put ("boolean" , "Boolean" );
213
- typeMapping .put ("Date" , "DateTime " );
213
+ typeMapping .put ("Date" , "Date " );
214
214
typeMapping .put ("DateTime" , "DateTime" );
215
215
typeMapping .put ("file" , "String" );
216
216
typeMapping .put ("map" , "Map" );
@@ -575,7 +575,12 @@ public String getTypeDeclaration(Schema p) {
575
575
} else if (ModelUtils .isBooleanSchema (p )) {
576
576
return "boolean()" ;
577
577
} else if (!StringUtils .isEmpty (p .get$ref ())) {
578
- return this .moduleName + ".Model." + super .getTypeDeclaration (p ) + ".t" ;
578
+ switch (super .getTypeDeclaration (p )) {
579
+ case "String" :
580
+ return "String.t" ;
581
+ default :
582
+ return this .moduleName + ".Model." + super .getTypeDeclaration (p ) + ".t" ;
583
+ }
579
584
} else if (ModelUtils .isFileSchema (p )) {
580
585
return "String.t" ;
581
586
} else if (ModelUtils .isStringSchema (p )) {
@@ -662,28 +667,23 @@ public String codeMappingKey() {
662
667
}
663
668
664
669
public String decodedStruct () {
665
- // Let Poison decode the entire response into a generic blob
670
+ // Let Jason decode the entire response into a generic blob
666
671
if (isMap ) {
667
672
return "%{}" ;
668
673
}
674
+
669
675
// Primitive return type, don't even try to decode
670
676
if (baseType == null || (containerType == null && primitiveType )) {
671
677
return "false" ;
672
678
} else if (isArray && languageSpecificPrimitives ().contains (baseType )) {
673
679
return "[]" ;
674
680
}
681
+
675
682
StringBuilder sb = new StringBuilder ();
676
- if (isArray ) {
677
- sb .append ("[" );
678
- }
679
- sb .append ("%" );
680
683
sb .append (moduleName );
681
684
sb .append (".Model." );
682
685
sb .append (baseType );
683
- sb .append ("{}" );
684
- if (isArray ) {
685
- sb .append ("]" );
686
- }
686
+
687
687
return sb .toString ();
688
688
}
689
689
@@ -768,6 +768,24 @@ public void setReplacedPathName(String replacedPathName) {
768
768
this .replacedPathName = replacedPathName ;
769
769
}
770
770
771
+ private void translateBaseType (StringBuilder returnEntry , String baseType ) {
772
+ switch (baseType ) {
773
+ case "AnyType" :
774
+ returnEntry .append ("any()" );
775
+ break ;
776
+ case "Boolean" :
777
+ returnEntry .append ("boolean()" );
778
+ break ;
779
+ case "Float" :
780
+ returnEntry .append ("float()" );
781
+ break ;
782
+ default :
783
+ returnEntry .append (baseType );
784
+ returnEntry .append (".t" );
785
+ break ;
786
+ }
787
+ }
788
+
771
789
public String typespec () {
772
790
StringBuilder sb = new StringBuilder ("@spec " );
773
791
sb .append (underscore (operationId ));
@@ -793,12 +811,7 @@ public String typespec() {
793
811
returnEntry .append (".Model." );
794
812
}
795
813
796
- if (exResponse .baseType .equals ("AnyType" )) {
797
- returnEntry .append ("any()" );
798
- }else {
799
- returnEntry .append (exResponse .baseType );
800
- returnEntry .append (".t" );
801
- }
814
+ translateBaseType (returnEntry , exResponse .baseType );
802
815
} else {
803
816
if (exResponse .containerType .equals ("array" ) ||
804
817
exResponse .containerType .equals ("set" )) {
@@ -808,12 +821,8 @@ public String typespec() {
808
821
returnEntry .append (".Model." );
809
822
}
810
823
811
- if (exResponse .baseType .equals ("AnyType" )) {
812
- returnEntry .append ("any())" );
813
- }else {
814
- returnEntry .append (exResponse .baseType );
815
- returnEntry .append (".t)" );
816
- }
824
+ translateBaseType (returnEntry , exResponse .baseType );
825
+ returnEntry .append (")" );
817
826
} else if (exResponse .containerType .equals ("map" )) {
818
827
returnEntry .append ("map()" );
819
828
}
0 commit comments