forked from loafle/openapi-generator-original
rollback android template
This commit is contained in:
parent
a8f6044c9b
commit
ab9daaacd6
@ -58,17 +58,11 @@ import java.io.File;
|
|||||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
Map
|
Map<String, String> queryParams = new HashMap<String, String>();
|
||||||
<String, String> queryParams = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
// header params
|
// header params
|
||||||
Map
|
Map<String, String> headerParams = new HashMap<String, String>();
|
||||||
<String, String> headerParams = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
// form params
|
// form params
|
||||||
Map
|
Map<String, String> formParams = new HashMap<String, String>();
|
||||||
<String, String> formParams = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
|
|
||||||
{{#queryParams}}if ({{paramName}} != null)
|
{{#queryParams}}if ({{paramName}} != null)
|
||||||
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||||
|
@ -53,9 +53,7 @@ import com.google.gson.JsonParseException;
|
|||||||
|
|
||||||
public class ApiInvoker {
|
public class ApiInvoker {
|
||||||
private static ApiInvoker INSTANCE = new ApiInvoker();
|
private static ApiInvoker INSTANCE = new ApiInvoker();
|
||||||
private Map
|
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||||
<String, String> defaultHeaderMap = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
|
|
||||||
private HttpClient client = null;
|
private HttpClient client = null;
|
||||||
|
|
||||||
@ -186,10 +184,7 @@ throw new ApiException(500, e.getMessage());
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String invokeAPI(String host, String path, String method, Map
|
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
|
||||||
<String, String> queryParams, Object body, Map
|
|
||||||
<String, String> headerParams, Map
|
|
||||||
<String, String> formParams, String contentType) throws ApiException {
|
|
||||||
HttpClient client = getClient(host);
|
HttpClient client = getClient(host);
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
@ -205,9 +200,7 @@ b.append(escapeString(key)).append("=").append(escapeString(value));
|
|||||||
}
|
}
|
||||||
String url = host + path + b.toString();
|
String url = host + path + b.toString();
|
||||||
|
|
||||||
HashMap
|
HashMap<String, String> headers = new HashMap<String, String>();
|
||||||
<String, String> headers = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
|
|
||||||
for(String key : headerParams.keySet()) {
|
for(String key : headerParams.keySet()) {
|
||||||
headers.put(key, headerParams.get(key));
|
headers.put(key, headerParams.get(key));
|
||||||
|
@ -24,13 +24,11 @@ public static String serialize(Object obj){
|
|||||||
return getGson().toJson(obj);
|
return getGson().toJson(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static
|
public static <T> T deserializeToList(String jsonString, Class cls){
|
||||||
<T> T deserializeToList(String jsonString, Class cls){
|
|
||||||
return getGson().fromJson(jsonString, getListTypeForDeserialization(cls));
|
return getGson().fromJson(jsonString, getListTypeForDeserialization(cls));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static
|
public static <T> T deserializeToObject(String jsonString, Class cls){
|
||||||
<T> T deserializeToObject(String jsonString, Class cls){
|
|
||||||
return getGson().fromJson(jsonString, getTypeForDeserialization(cls));
|
return getGson().fromJson(jsonString, getTypeForDeserialization(cls));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,14 +36,10 @@ public static
|
|||||||
String className = cls.getSimpleName();
|
String className = cls.getSimpleName();
|
||||||
{{#models}}{{#model}}
|
{{#models}}{{#model}}
|
||||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||||
return new TypeToken
|
return new TypeToken<List<{{classname}}>>(){}.getType();
|
||||||
<List
|
|
||||||
<{{classname}}>>(){}.getType();
|
|
||||||
}
|
}
|
||||||
{{/model}}{{/models}}
|
{{/model}}{{/models}}
|
||||||
return new TypeToken
|
return new TypeToken<List<Object>>(){}.getType();
|
||||||
<List
|
|
||||||
<Object>>(){}.getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type getTypeForDeserialization(Class cls) {
|
public static Type getTypeForDeserialization(Class cls) {
|
||||||
@ -55,8 +49,7 @@ public static
|
|||||||
return new TypeToken<{{classname}}>(){}.getType();
|
return new TypeToken<{{classname}}>(){}.getType();
|
||||||
}
|
}
|
||||||
{{/model}}{{/models}}
|
{{/model}}{{/models}}
|
||||||
return new TypeToken
|
return new TypeToken<Object>(){}.getType();
|
||||||
<Object>(){}.getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -77,8 +77,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>
|
<source>src/main/java</source>
|
||||||
src/main/java</source>
|
|
||||||
</sources>
|
</sources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -90,8 +89,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>
|
<source>src/test/java</source>
|
||||||
src/test/java</source>
|
|
||||||
</sources>
|
</sources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -102,8 +100,7 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.3.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>
|
<source>1.6</source>
|
||||||
1.6</source>
|
|
||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user