forked from loafle/openapi-generator-original
Fixed encoding issues with query and path parameters in java and scala code gen.
This commit is contained in:
parent
7f735fa1ce
commit
7d915e4b23
@ -9,6 +9,11 @@
|
|||||||
"username":"testuser2",
|
"username":"testuser2",
|
||||||
"password":"password2",
|
"password":"password2",
|
||||||
"email":"test2@dummy.com"
|
"email":"test2@dummy.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username":"user?10",
|
||||||
|
"password":"password2",
|
||||||
|
"email":"test2@dummy.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"petList":[
|
"petList":[
|
||||||
|
@ -164,6 +164,21 @@
|
|||||||
"expectedOutput" : "EXCEPTION"
|
"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}"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ $method.queryParameters:{ argument |
|
|||||||
}$
|
}$
|
||||||
$method.pathParameters:{ argument |
|
$method.pathParameters:{ argument |
|
||||||
if( $argument.name$ != null) {
|
if( $argument.name$ != null) {
|
||||||
resourcePath = resourcePath.replace("{$argument.name$}", $argument.name$);
|
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.name$));
|
||||||
}
|
}
|
||||||
}$
|
}$
|
||||||
$method.headerParameters:{ argument |
|
$method.headerParameters:{ argument |
|
||||||
@ -96,7 +96,7 @@ $method.queryParameters:{ argument |
|
|||||||
}$
|
}$
|
||||||
$method.pathParameters:{ argument |
|
$method.pathParameters:{ argument |
|
||||||
if( $argument.inputModelClassArgument$ != null && $argument.methodNameFromModelClass$ != null) {
|
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 |
|
$method.headerParameters:{ argument |
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
package com.wordnik.swagger.common;
|
package com.wordnik.swagger.common;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -250,7 +252,8 @@ public class APIInvoker {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String toPathValue(String value) {
|
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) {
|
public static String toPathValue(List objects) {
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
|
String output = "";
|
||||||
for(Object o: objects){
|
for(Object o: objects){
|
||||||
out.append(o.toString());
|
out.append(o.toString());
|
||||||
out.append(",");
|
out.append(",");
|
||||||
}
|
}
|
||||||
if(out.indexOf(",") != -1) {
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ $method.headerParameters:{ argument |
|
|||||||
}$
|
}$
|
||||||
$method.pathParameters:{ argument |
|
$method.pathParameters:{ argument |
|
||||||
if(null != $argument.name$) {
|
if(null != $argument.name$) {
|
||||||
resourcePath = resourcePath.replace("{$argument.name$}", $argument.name$)
|
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.name$))
|
||||||
}
|
}
|
||||||
}$
|
}$
|
||||||
$endif$
|
$endif$
|
||||||
@ -98,7 +98,7 @@ $method.headerParameters:{ argument |
|
|||||||
}$
|
}$
|
||||||
$method.pathParameters:{ argument |
|
$method.pathParameters:{ argument |
|
||||||
if(null != $argument.inputModelClassArgument$ && null != $argument.methodNameFromModelClass$ ) {
|
if(null != $argument.inputModelClassArgument$ && null != $argument.methodNameFromModelClass$ ) {
|
||||||
resourcePath = resourcePath.replace("{$argument.name$}", $argument.methodNameFromModelClass$)
|
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.methodNameFromModelClass$))
|
||||||
}
|
}
|
||||||
}$
|
}$
|
||||||
$endif$
|
$endif$
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
package com.wordnik.swagger.runtime.common;
|
package com.wordnik.swagger.runtime.common;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -273,7 +275,8 @@ public class APIInvoker {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String toPathValue(String value) {
|
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) {
|
public static String toPathValue(List objects) {
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
|
String output = "";
|
||||||
for(Object o: objects){
|
for(Object o: objects){
|
||||||
out.append(o.toString());
|
out.append(o.toString());
|
||||||
out.append(",");
|
out.append(",");
|
||||||
}
|
}
|
||||||
if(out.indexOf(",") != -1) {
|
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() {
|
public boolean isLoggingEnable() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user