Fixed encoding issues with query and path parameters in java and scala code gen.

This commit is contained in:
rpidikiti 2012-01-23 12:45:23 -08:00
parent 7f735fa1ce
commit 7d915e4b23
6 changed files with 54 additions and 10 deletions

View File

@ -9,6 +9,11 @@
"username":"testuser2",
"password":"password2",
"email":"test2@dummy.com"
},
{
"username":"user?10",
"password":"password2",
"email":"test2@dummy.com"
}
],
"petList":[

View File

@ -164,6 +164,21 @@
"expectedOutput" : "EXCEPTION"
}
]
},
{
"name" : "Find user by name with special characters",
"id" : 5,
"resourceId" : 9,
"input" : {
"username":"${input.userList[2].username}"
},
"assertions" : [
{
"actualOutput" : "${output(1.5).username}",
"condition" : "==",
"expectedOutput" : "${input.userList[2].username}"
}
]
}

View File

@ -78,7 +78,7 @@ $method.queryParameters:{ argument |
}$
$method.pathParameters:{ argument |
if( $argument.name$ != null) {
resourcePath = resourcePath.replace("{$argument.name$}", $argument.name$);
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.name$));
}
}$
$method.headerParameters:{ argument |
@ -96,7 +96,7 @@ $method.queryParameters:{ argument |
}$
$method.pathParameters:{ argument |
if( $argument.inputModelClassArgument$ != null && $argument.methodNameFromModelClass$ != null) {
resourcePath = resourcePath.replace("{$argument.name$}", $argument.methodNameFromModelClass$);
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.methodNameFromModelClass$));
}
}$
$method.headerParameters:{ argument |

View File

@ -17,7 +17,9 @@
package com.wordnik.swagger.common;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.String;
import java.net.URLEncoder;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
@ -250,7 +252,8 @@ public class APIInvoker {
* @return
*/
public static String toPathValue(String value) {
return value == null ? "" : value;
value = (value == null) ? "" : value;
return encode(value);
}
/**
@ -261,13 +264,22 @@ public class APIInvoker {
*/
public static String toPathValue(List objects) {
StringBuilder out = new StringBuilder();
String output = "";
for(Object o: objects){
out.append(o.toString());
out.append(",");
}
if(out.indexOf(",") != -1) {
return out.substring(0, out.lastIndexOf(",") );
output = out.substring(0, out.lastIndexOf(",") );
}
return encode(output);
}
private static String encode(String value){
try{
return URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20");
}catch(UnsupportedEncodingException uee){
throw new RuntimeException(uee.getMessage());
}
return out.toString();
}
}

View File

@ -81,7 +81,7 @@ $method.headerParameters:{ argument |
}$
$method.pathParameters:{ argument |
if(null != $argument.name$) {
resourcePath = resourcePath.replace("{$argument.name$}", $argument.name$)
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.name$))
}
}$
$endif$
@ -98,7 +98,7 @@ $method.headerParameters:{ argument |
}$
$method.pathParameters:{ argument |
if(null != $argument.inputModelClassArgument$ && null != $argument.methodNameFromModelClass$ ) {
resourcePath = resourcePath.replace("{$argument.name$}", $argument.methodNameFromModelClass$)
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.methodNameFromModelClass$))
}
}$
$endif$

View File

@ -17,7 +17,9 @@
package com.wordnik.swagger.runtime.common;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.String;
import java.net.URLEncoder;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
@ -273,7 +275,8 @@ public class APIInvoker {
* @return
*/
public static String toPathValue(String value) {
return value == null ? "" : value;
value = (value == null) ? "" : value;
return encode(value);
}
/**
@ -284,14 +287,23 @@ public class APIInvoker {
*/
public static String toPathValue(List objects) {
StringBuilder out = new StringBuilder();
String output = "";
for(Object o: objects){
out.append(o.toString());
out.append(",");
}
if(out.indexOf(",") != -1) {
return out.substring(0, out.lastIndexOf(",") );
output = out.substring(0, out.lastIndexOf(",") );
}
return encode(output);
}
private static String encode(String value){
try{
return URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20");
}catch(UnsupportedEncodingException uee){
throw new RuntimeException(uee.getMessage());
}
return out.toString();
}
public boolean isLoggingEnable() {