Skip to content

Commit 218e671

Browse files
committed
Don't send 0 for numeric parmeters that have not been specified (or false for boolean).
Parameters should be boxed (object type) in internal storage, so if the user did not specify the parameter, we will not assume the value is 0 - as in ARI not specifying an optional param often has more meaning than "zero". For example, in `POST /channels` ("channel originate"), not setting the priority means "1" and not "0".
1 parent 5fde7b6 commit 218e671

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

codegen/src/main/java/ch/loway/oss/ari4java/codegen/DefMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ private Apis loadApis(JsonNode apis, File f, String apiVersion) throws IOExcepti
433433
for (JsonNode parameter : parameters) {
434434
Operation.Param p = new Operation.Param();
435435
p.javaType = remapAbstractType(txt(parameter.get("dataType")));
436+
p.methodArgumentType = JavaPkgInfo.primitiveSignature.containsKey(p.javaType) ?
437+
JavaPkgInfo.primitiveSignature.get(p.javaType) : p.javaType;
436438
p.name = txt(parameter.get("name"));
437439
p.required = txt(parameter.get("required")).equalsIgnoreCase("true");
438440
p.type = Operation.ParamType.build(txt(parameter.get("paramType")));

codegen/src/main/java/ch/loway/oss/ari4java/codegen/genJava/JavaPkgInfo.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@
1010
public class JavaPkgInfo {
1111

1212
public final static Map<String, String> TypeMap;
13+
public final static Map<String, String> primitiveSignature;
1314

1415
static {
1516
TypeMap = new HashMap<String, String>();
1617
TypeMap.put("string", "String");
17-
TypeMap.put("long", "long");
18-
TypeMap.put("int", "int");
19-
TypeMap.put("double", "double");
18+
TypeMap.put("long", "Long");
19+
TypeMap.put("int", "Integer");
20+
TypeMap.put("double", "Double");
2021
TypeMap.put("date", "Date");
2122
TypeMap.put("object", "Object");
22-
TypeMap.put("boolean", "boolean");
23+
TypeMap.put("boolean", "Boolean");
2324
TypeMap.put("binary", "byte[]");
2425
TypeMap.put("containers", "Map<String,String>");
26+
27+
primitiveSignature = new HashMap<String, String>();
28+
primitiveSignature.put("Boolean", "boolean");
29+
primitiveSignature.put("Integer", "int");
30+
primitiveSignature.put("Long", "long");
31+
primitiveSignature.put("Double", "double");
2532
}
2633

27-
2834
String base = "ch.loway.oss.ari4java.generated";
2935
public String className = "";
3036
public String apiVersion = "";

codegen/src/main/java/ch/loway/oss/ari4java/codegen/models/Operation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public static class Param {
296296
public String name = "";
297297
public ParamType type = ParamType.PATH;
298298
public String javaType = "";
299+
public String methodArgumentType = "";
299300
public boolean required = true;
300301

301302
public String getSignature(String returnType) {
@@ -308,7 +309,7 @@ public String getSignature(String returnType) {
308309
public String getDefinition(String returnType) {
309310
StringBuilder sb = new StringBuilder();
310311
sb.append(" public ").append(returnType).append(" ").append(JavaGen.addPrefixAndCapitalize("set", name))
311-
.append("(").append(javaType).append(" ").append(name).append(")");
312+
.append("(").append(methodArgumentType).append(" ").append(name).append(")");
312313
return sb.toString();
313314
}
314315

src/main/java/ch/loway/oss/ari4java/tools/HttpParam.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@ public static List<ch.loway.oss.ari4java.tools.HttpParam> build(String key, Map<
3131
return vars;
3232
}
3333

34-
public static HttpParam build(String n, int v) {
34+
public static HttpParam build(String n, Integer v) {
35+
if (null == v)
36+
return build(n, (String)null);
3537
return build(n, Integer.toString(v));
3638
}
3739

38-
public static HttpParam build(String n, long v) {
40+
public static HttpParam build(String n, Long v) {
41+
if (null == v)
42+
return build(n, (String)null);
3943
return build(n, Long.toString(v));
4044
}
4145

42-
public static HttpParam build(String n, boolean v) {
46+
public static HttpParam build(String n, Boolean v) {
47+
if (null == v)
48+
return build(n, (String)null);
4349
return build(n, v ? "true" : "false");
4450
}
4551

0 commit comments

Comments
 (0)