forked from loafle/openapi-generator-original
rollback android template
This commit is contained in:
parent
a8f6044c9b
commit
ab9daaacd6
@ -18,103 +18,97 @@ import java.util.HashMap;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
public class {{classname}} {
|
public class {{classname}} {
|
||||||
String basePath = "{{basePath}}";
|
String basePath = "{{basePath}}";
|
||||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||||
|
|
||||||
public void addHeader(String key, String value) {
|
public void addHeader(String key, String value) {
|
||||||
getInvoker().addDefaultHeader(key, value);
|
getInvoker().addDefaultHeader(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiInvoker getInvoker() {
|
public ApiInvoker getInvoker() {
|
||||||
return apiInvoker;
|
return apiInvoker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBasePath(String basePath) {
|
public void setBasePath(String basePath) {
|
||||||
this.basePath = basePath;
|
this.basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBasePath() {
|
public String getBasePath() {
|
||||||
return basePath;
|
return basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
{{#operation}}
|
||||||
|
/**
|
||||||
|
* {{summary}}
|
||||||
|
* {{notes}}
|
||||||
|
{{#allParams}} * @param {{paramName}} {{description}}
|
||||||
|
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||||
|
*/
|
||||||
|
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||||
|
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||||
|
{{#allParams}}{{#required}}
|
||||||
|
// verify the required parameter '{{paramName}}' is set
|
||||||
|
if ({{paramName}} == null) {
|
||||||
|
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
|
||||||
|
}
|
||||||
|
{{/required}}{{/allParams}}
|
||||||
|
|
||||||
|
// create path and map variables
|
||||||
|
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||||
|
|
||||||
|
// query params
|
||||||
|
Map<String, String> queryParams = new HashMap<String, String>();
|
||||||
|
// header params
|
||||||
|
Map<String, String> headerParams = new HashMap<String, String>();
|
||||||
|
// form params
|
||||||
|
Map<String, String> formParams = new HashMap<String, String>();
|
||||||
|
|
||||||
|
{{#queryParams}}if ({{paramName}} != null)
|
||||||
|
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||||
|
{{/queryParams}}
|
||||||
|
|
||||||
|
{{#headerParams}}headerParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||||
|
{{/headerParams}}
|
||||||
|
|
||||||
|
String[] contentTypes = {
|
||||||
|
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
|
||||||
|
};
|
||||||
|
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||||
|
|
||||||
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
|
// file uploading
|
||||||
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||||
|
{{#formParams}}{{#notFile}}
|
||||||
|
if ({{paramName}} != null) {
|
||||||
|
builder.addTextBody("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), ApiInvoker.TEXT_PLAIN_UTF8);
|
||||||
|
}
|
||||||
|
{{/notFile}}{{#isFile}}
|
||||||
|
if ({{paramName}} != null) {
|
||||||
|
builder.addBinaryBody("{{baseName}}", {{paramName}});
|
||||||
|
}
|
||||||
|
{{/isFile}}{{/formParams}}
|
||||||
|
|
||||||
|
HttpEntity httpEntity = builder.build();
|
||||||
|
postBody = httpEntity;
|
||||||
|
} else {
|
||||||
|
// normal form params
|
||||||
|
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));{{/notFile}}
|
||||||
|
{{/formParams}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#operation}}
|
try {
|
||||||
/**
|
String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, contentType);
|
||||||
* {{summary}}
|
if(response != null){
|
||||||
* {{notes}}
|
|
||||||
{{#allParams}} * @param {{paramName}} {{description}}
|
|
||||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
|
||||||
*/
|
|
||||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
|
||||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
|
||||||
{{#allParams}}{{#required}}
|
|
||||||
// verify the required parameter '{{paramName}}' is set
|
|
||||||
if ({{paramName}} == null) {
|
|
||||||
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
|
|
||||||
}
|
|
||||||
{{/required}}{{/allParams}}
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
|
||||||
|
|
||||||
// query params
|
|
||||||
Map
|
|
||||||
<String, String> queryParams = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
// header params
|
|
||||||
Map
|
|
||||||
<String, String> headerParams = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
// form params
|
|
||||||
Map
|
|
||||||
<String, String> formParams = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
|
|
||||||
{{#queryParams}}if ({{paramName}} != null)
|
|
||||||
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
|
||||||
{{/queryParams}}
|
|
||||||
|
|
||||||
{{#headerParams}}headerParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
|
||||||
{{/headerParams}}
|
|
||||||
|
|
||||||
String[] contentTypes = {
|
|
||||||
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
|
|
||||||
};
|
|
||||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
|
||||||
|
|
||||||
if (contentType.startsWith("multipart/form-data")) {
|
|
||||||
// file uploading
|
|
||||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
||||||
{{#formParams}}{{#notFile}}
|
|
||||||
if ({{paramName}} != null) {
|
|
||||||
builder.addTextBody("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), ApiInvoker.TEXT_PLAIN_UTF8);
|
|
||||||
}
|
|
||||||
{{/notFile}}{{#isFile}}
|
|
||||||
if ({{paramName}} != null) {
|
|
||||||
builder.addBinaryBody("{{baseName}}", {{paramName}});
|
|
||||||
}
|
|
||||||
{{/isFile}}{{/formParams}}
|
|
||||||
|
|
||||||
HttpEntity httpEntity = builder.build();
|
|
||||||
postBody = httpEntity;
|
|
||||||
} else {
|
|
||||||
// normal form params
|
|
||||||
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));{{/notFile}}
|
|
||||||
{{/formParams}}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, contentType);
|
|
||||||
if(response != null){
|
|
||||||
return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return {{#returnType}}null{{/returnType}};
|
return {{#returnType}}null{{/returnType}};
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
|
||||||
}
|
|
||||||
{{/operation}}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
{{/operation}}
|
||||||
|
}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
package {{invokerPackage}};
|
package {{invokerPackage}};
|
||||||
|
|
||||||
public class ApiException extends Exception {
|
public class ApiException extends Exception {
|
||||||
int code = 0;
|
int code = 0;
|
||||||
String message = null;
|
String message = null;
|
||||||
|
|
||||||
public ApiException() {}
|
public ApiException() {}
|
||||||
|
|
||||||
public ApiException(int code, String message) {
|
public ApiException(int code, String message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCode(int code) {
|
public void setCode(int code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(String message) {
|
public void setMessage(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -52,345 +52,338 @@ import javax.net.ssl.X509TrustManager;
|
|||||||
import com.google.gson.JsonParseException;
|
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;
|
||||||
|
|
||||||
private boolean ignoreSSLCertificates = false;
|
private boolean ignoreSSLCertificates = false;
|
||||||
|
|
||||||
private ClientConnectionManager ignoreSSLConnectionManager;
|
private ClientConnectionManager ignoreSSLConnectionManager;
|
||||||
|
|
||||||
/** Content type "text/plain" with UTF-8 encoding. */
|
/** Content type "text/plain" with UTF-8 encoding. */
|
||||||
public static final ContentType TEXT_PLAIN_UTF8 = ContentType.create("text/plain", Consts.UTF_8);
|
public static final ContentType TEXT_PLAIN_UTF8 = ContentType.create("text/plain", Consts.UTF_8);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ISO 8601 date time format.
|
* ISO 8601 date time format.
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_8601
|
* @see https://en.wikipedia.org/wiki/ISO_8601
|
||||||
*/
|
*/
|
||||||
public static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
public static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ISO 8601 date format.
|
* ISO 8601 date format.
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_8601
|
* @see https://en.wikipedia.org/wiki/ISO_8601
|
||||||
*/
|
*/
|
||||||
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Use UTC as the default time zone.
|
// Use UTC as the default time zone.
|
||||||
DATE_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
DATE_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
||||||
// Set default User-Agent.
|
// Set default User-Agent.
|
||||||
setUserAgent("Android-Java-Swagger");
|
setUserAgent("Android-Java-Swagger");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUserAgent(String userAgent) {
|
public static void setUserAgent(String userAgent) {
|
||||||
INSTANCE.addDefaultHeader("User-Agent", userAgent);
|
INSTANCE.addDefaultHeader("User-Agent", userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Date parseDateTime(String str) {
|
public static Date parseDateTime(String str) {
|
||||||
try {
|
try {
|
||||||
return DATE_TIME_FORMAT.parse(str);
|
return DATE_TIME_FORMAT.parse(str);
|
||||||
} catch (java.text.ParseException e) {
|
} catch (java.text.ParseException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Date parseDate(String str) {
|
public static Date parseDate(String str) {
|
||||||
try {
|
try {
|
||||||
return DATE_FORMAT.parse(str);
|
return DATE_FORMAT.parse(str);
|
||||||
} catch (java.text.ParseException e) {
|
} catch (java.text.ParseException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatDateTime(Date datetime) {
|
public static String formatDateTime(Date datetime) {
|
||||||
return DATE_TIME_FORMAT.format(datetime);
|
return DATE_TIME_FORMAT.format(datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatDate(Date date) {
|
public static String formatDate(Date date) {
|
||||||
return DATE_FORMAT.format(date);
|
return DATE_FORMAT.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parameterToString(Object param) {
|
public static String parameterToString(Object param) {
|
||||||
if (param == null) {
|
if (param == null) {
|
||||||
return "";
|
return "";
|
||||||
} else if (param instanceof Date) {
|
} else if (param instanceof Date) {
|
||||||
return formatDateTime((Date) param);
|
return formatDateTime((Date) param);
|
||||||
} else if (param instanceof Collection) {
|
} else if (param instanceof Collection) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(Object o : (Collection)param) {
|
for(Object o : (Collection)param) {
|
||||||
if(b.length() > 0) {
|
if(b.length() > 0) {
|
||||||
b.append(",");
|
b.append(",");
|
||||||
}
|
}
|
||||||
b.append(String.valueOf(o));
|
b.append(String.valueOf(o));
|
||||||
}
|
}
|
||||||
return b.toString();
|
return b.toString();
|
||||||
} else {
|
} else {
|
||||||
return String.valueOf(param);
|
return String.valueOf(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiInvoker() {
|
public ApiInvoker() {
|
||||||
initConnectionManager();
|
initConnectionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApiInvoker getInstance() {
|
public static ApiInvoker getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ignoreSSLCertificates(boolean ignoreSSLCertificates) {
|
public void ignoreSSLCertificates(boolean ignoreSSLCertificates) {
|
||||||
this.ignoreSSLCertificates = ignoreSSLCertificates;
|
this.ignoreSSLCertificates = ignoreSSLCertificates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDefaultHeader(String key, String value) {
|
public void addDefaultHeader(String key, String value) {
|
||||||
defaultHeaderMap.put(key, value);
|
defaultHeaderMap.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String escapeString(String str) {
|
public String escapeString(String str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||||
try{
|
try{
|
||||||
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
|
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
|
||||||
return JsonUtil.deserializeToList(json, cls);
|
return JsonUtil.deserializeToList(json, cls);
|
||||||
}
|
}
|
||||||
else if(String.class.equals(cls)) {
|
else if(String.class.equals(cls)) {
|
||||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||||
return json.substring(1, json.length() - 2);
|
return json.substring(1, json.length() - 2);
|
||||||
else
|
else
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return JsonUtil.deserializeToObject(json, cls);
|
return JsonUtil.deserializeToObject(json, cls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (JsonParseException e) {
|
catch (JsonParseException e) {
|
||||||
throw new ApiException(500, e.getMessage());
|
throw new ApiException(500, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String serialize(Object obj) throws ApiException {
|
public static String serialize(Object obj) throws ApiException {
|
||||||
try {
|
try {
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
return JsonUtil.serialize(obj);
|
return JsonUtil.serialize(obj);
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new ApiException(500, e.getMessage());
|
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
|
HttpClient client = getClient(host);
|
||||||
<String, String> headerParams, Map
|
|
||||||
<String, String> formParams, String contentType) throws ApiException {
|
|
||||||
HttpClient client = getClient(host);
|
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(String key : queryParams.keySet()) {
|
for(String key : queryParams.keySet()) {
|
||||||
String value = queryParams.get(key);
|
String value = queryParams.get(key);
|
||||||
if (value != null){
|
if (value != null){
|
||||||
if(b.toString().length() == 0)
|
if(b.toString().length() == 0)
|
||||||
b.append("?");
|
b.append("?");
|
||||||
else
|
else
|
||||||
b.append("&");
|
b.append("&");
|
||||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(String key : defaultHeaderMap.keySet()) {
|
for(String key : defaultHeaderMap.keySet()) {
|
||||||
if(!headerParams.containsKey(key)) {
|
if(!headerParams.containsKey(key)) {
|
||||||
headers.put(key, defaultHeaderMap.get(key));
|
headers.put(key, defaultHeaderMap.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
headers.put("Accept", "application/json");
|
headers.put("Accept", "application/json");
|
||||||
|
|
||||||
// URL encoded string from form parameters
|
// URL encoded string from form parameters
|
||||||
String formParamStr = null;
|
String formParamStr = null;
|
||||||
|
|
||||||
// for form data
|
// for form data
|
||||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||||
StringBuilder formParamBuilder = new StringBuilder();
|
StringBuilder formParamBuilder = new StringBuilder();
|
||||||
|
|
||||||
// encode the form params
|
// encode the form params
|
||||||
for (String key : formParams.keySet()) {
|
for (String key : formParams.keySet()) {
|
||||||
String value = formParams.get(key);
|
String value = formParams.get(key);
|
||||||
if (value != null && !"".equals(value.trim())) {
|
if (value != null && !"".equals(value.trim())) {
|
||||||
if (formParamBuilder.length() > 0) {
|
if (formParamBuilder.length() > 0) {
|
||||||
formParamBuilder.append("&");
|
formParamBuilder.append("&");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
|
formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// move on to next
|
// move on to next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
formParamStr = formParamBuilder.toString();
|
formParamStr = formParamBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
if ("GET".equals(method)) {
|
if ("GET".equals(method)) {
|
||||||
HttpGet get = new HttpGet(url);
|
HttpGet get = new HttpGet(url);
|
||||||
get.addHeader("Accept", "application/json");
|
get.addHeader("Accept", "application/json");
|
||||||
for(String key : headers.keySet()) {
|
for(String key : headers.keySet()) {
|
||||||
get.setHeader(key, headers.get(key));
|
get.setHeader(key, headers.get(key));
|
||||||
}
|
}
|
||||||
response = client.execute(get);
|
response = client.execute(get);
|
||||||
}
|
}
|
||||||
else if ("POST".equals(method)) {
|
else if ("POST".equals(method)) {
|
||||||
HttpPost post = new HttpPost(url);
|
HttpPost post = new HttpPost(url);
|
||||||
if (formParamStr != null) {
|
if (formParamStr != null) {
|
||||||
post.setHeader("Content-Type", contentType);
|
post.setHeader("Content-Type", contentType);
|
||||||
post.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
post.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||||
} else if (body != null) {
|
} else if (body != null) {
|
||||||
if (body instanceof HttpEntity) {
|
if (body instanceof HttpEntity) {
|
||||||
// this is for file uploading
|
// this is for file uploading
|
||||||
post.setEntity((HttpEntity) body);
|
post.setEntity((HttpEntity) body);
|
||||||
} else {
|
} else {
|
||||||
post.setHeader("Content-Type", contentType);
|
post.setHeader("Content-Type", contentType);
|
||||||
post.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
post.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(String key : headers.keySet()) {
|
for(String key : headers.keySet()) {
|
||||||
post.setHeader(key, headers.get(key));
|
post.setHeader(key, headers.get(key));
|
||||||
}
|
}
|
||||||
response = client.execute(post);
|
response = client.execute(post);
|
||||||
}
|
}
|
||||||
else if ("PUT".equals(method)) {
|
else if ("PUT".equals(method)) {
|
||||||
HttpPut put = new HttpPut(url);
|
HttpPut put = new HttpPut(url);
|
||||||
if (formParamStr != null) {
|
if (formParamStr != null) {
|
||||||
put.setHeader("Content-Type", contentType);
|
put.setHeader("Content-Type", contentType);
|
||||||
put.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
put.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||||
} else if (body != null) {
|
} else if (body != null) {
|
||||||
put.setHeader("Content-Type", contentType);
|
put.setHeader("Content-Type", contentType);
|
||||||
put.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
put.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||||
}
|
}
|
||||||
for(String key : headers.keySet()) {
|
for(String key : headers.keySet()) {
|
||||||
put.setHeader(key, headers.get(key));
|
put.setHeader(key, headers.get(key));
|
||||||
}
|
}
|
||||||
response = client.execute(put);
|
response = client.execute(put);
|
||||||
}
|
}
|
||||||
else if ("DELETE".equals(method)) {
|
else if ("DELETE".equals(method)) {
|
||||||
HttpDelete delete = new HttpDelete(url);
|
HttpDelete delete = new HttpDelete(url);
|
||||||
for(String key : headers.keySet()) {
|
for(String key : headers.keySet()) {
|
||||||
delete.setHeader(key, headers.get(key));
|
delete.setHeader(key, headers.get(key));
|
||||||
}
|
}
|
||||||
response = client.execute(delete);
|
response = client.execute(delete);
|
||||||
}
|
}
|
||||||
else if ("PATCH".equals(method)) {
|
else if ("PATCH".equals(method)) {
|
||||||
HttpPatch patch = new HttpPatch(url);
|
HttpPatch patch = new HttpPatch(url);
|
||||||
if (formParamStr != null) {
|
if (formParamStr != null) {
|
||||||
patch.setHeader("Content-Type", contentType);
|
patch.setHeader("Content-Type", contentType);
|
||||||
patch.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
patch.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||||
} else if (body != null) {
|
} else if (body != null) {
|
||||||
patch.setHeader("Content-Type", contentType);
|
patch.setHeader("Content-Type", contentType);
|
||||||
patch.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
patch.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||||
}
|
}
|
||||||
for(String key : headers.keySet()) {
|
for(String key : headers.keySet()) {
|
||||||
patch.setHeader(key, headers.get(key));
|
patch.setHeader(key, headers.get(key));
|
||||||
}
|
}
|
||||||
response = client.execute(patch);
|
response = client.execute(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = response.getStatusLine().getStatusCode();
|
int code = response.getStatusLine().getStatusCode();
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
if(code == 204)
|
if(code == 204)
|
||||||
responseString = "";
|
responseString = "";
|
||||||
else if(code >= 200 && code < 300) {
|
else if(code >= 200 && code < 300) {
|
||||||
if(response.getEntity() != null) {
|
if(response.getEntity() != null) {
|
||||||
HttpEntity resEntity = response.getEntity();
|
HttpEntity resEntity = response.getEntity();
|
||||||
responseString = EntityUtils.toString(resEntity);
|
responseString = EntityUtils.toString(resEntity);
|
||||||
}
|
}
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(response.getEntity() != null) {
|
if(response.getEntity() != null) {
|
||||||
HttpEntity resEntity = response.getEntity();
|
HttpEntity resEntity = response.getEntity();
|
||||||
responseString = EntityUtils.toString(resEntity);
|
responseString = EntityUtils.toString(resEntity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
responseString = "no data";
|
responseString = "no data";
|
||||||
}
|
}
|
||||||
throw new ApiException(code, responseString);
|
throw new ApiException(code, responseString);
|
||||||
}
|
}
|
||||||
catch(IOException e) {
|
catch(IOException e) {
|
||||||
throw new ApiException(500, e.getMessage());
|
throw new ApiException(500, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpClient getClient(String host) {
|
private HttpClient getClient(String host) {
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
if (ignoreSSLCertificates && ignoreSSLConnectionManager != null) {
|
if (ignoreSSLCertificates && ignoreSSLConnectionManager != null) {
|
||||||
// Trust self signed certificates
|
// Trust self signed certificates
|
||||||
client = new DefaultHttpClient(ignoreSSLConnectionManager, new BasicHttpParams());
|
client = new DefaultHttpClient(ignoreSSLConnectionManager, new BasicHttpParams());
|
||||||
} else {
|
} else {
|
||||||
client = new DefaultHttpClient();
|
client = new DefaultHttpClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initConnectionManager() {
|
private void initConnectionManager() {
|
||||||
try {
|
try {
|
||||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||||
|
|
||||||
// set up a TrustManager that trusts everything
|
// set up a TrustManager that trusts everything
|
||||||
TrustManager[] trustManagers = new TrustManager[] {
|
TrustManager[] trustManagers = new TrustManager[] {
|
||||||
new X509TrustManager() {
|
new X509TrustManager() {
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
|
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
|
||||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
|
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
sslContext.init(null, trustManagers, new SecureRandom());
|
sslContext.init(null, trustManagers, new SecureRandom());
|
||||||
|
|
||||||
SSLSocketFactory sf = new SSLSocketFactory((KeyStore)null) {
|
SSLSocketFactory sf = new SSLSocketFactory((KeyStore)null) {
|
||||||
private javax.net.ssl.SSLSocketFactory sslFactory = sslContext.getSocketFactory();
|
private javax.net.ssl.SSLSocketFactory sslFactory = sslContext.getSocketFactory();
|
||||||
|
|
||||||
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
|
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
|
||||||
throws IOException, UnknownHostException {
|
throws IOException, UnknownHostException {
|
||||||
return sslFactory.createSocket(socket, host, port, autoClose);
|
return sslFactory.createSocket(socket, host, port, autoClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Socket createSocket() throws IOException {
|
public Socket createSocket() throws IOException {
|
||||||
return sslFactory.createSocket();
|
return sslFactory.createSocket();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
Scheme httpsScheme = new Scheme("https", sf, 443);
|
Scheme httpsScheme = new Scheme("https", sf, 443);
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(httpsScheme);
|
schemeRegistry.register(httpsScheme);
|
||||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
ignoreSSLConnectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry);
|
ignoreSSLConnectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
// This will only be thrown if SSL isn't available for some reason.
|
// This will only be thrown if SSL isn't available for some reason.
|
||||||
} catch (KeyManagementException e) {
|
} catch (KeyManagementException e) {
|
||||||
// This might be thrown when passing a key into init(), but no key is being passed.
|
// This might be thrown when passing a key into init(), but no key is being passed.
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
// This catches anything else that might go wrong.
|
// This catches anything else that might go wrong.
|
||||||
// If anything goes wrong we default to the standard connection manager.
|
// If anything goes wrong we default to the standard connection manager.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,93 +1,93 @@
|
|||||||
{{#useAndroidMavenGradlePlugin}}
|
{{#useAndroidMavenGradlePlugin}}
|
||||||
group = '{{groupId}}'
|
group = '{{groupId}}'
|
||||||
project.version = '{{artifactVersion}}'
|
project.version = '{{artifactVersion}}'
|
||||||
{{/useAndroidMavenGradlePlugin}}
|
{{/useAndroidMavenGradlePlugin}}
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.2.2'
|
classpath 'com.android.tools.build:gradle:1.2.2'
|
||||||
{{#useAndroidMavenGradlePlugin}}
|
{{#useAndroidMavenGradlePlugin}}
|
||||||
classpath 'com.github.dcendents:android-maven-plugin:1.2'
|
classpath 'com.github.dcendents:android-maven-plugin:1.2'
|
||||||
{{/useAndroidMavenGradlePlugin}}
|
{{/useAndroidMavenGradlePlugin}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
{{#useAndroidMavenGradlePlugin}}
|
{{#useAndroidMavenGradlePlugin}}
|
||||||
apply plugin: 'com.github.dcendents.android-maven'
|
apply plugin: 'com.github.dcendents.android-maven'
|
||||||
{{/useAndroidMavenGradlePlugin}}
|
{{/useAndroidMavenGradlePlugin}}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 22
|
compileSdkVersion 22
|
||||||
buildToolsVersion '22.0.0'
|
buildToolsVersion '22.0.0'
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 22
|
targetSdkVersion 22
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the aar correctly
|
// Rename the aar correctly
|
||||||
libraryVariants.all { variant ->
|
libraryVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
def outputFile = output.outputFile
|
def outputFile = output.outputFile
|
||||||
if (outputFile != null && outputFile.name.endsWith('.aar')) {
|
if (outputFile != null && outputFile.name.endsWith('.aar')) {
|
||||||
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
|
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
|
||||||
output.outputFile = new File(outputFile.parent, fileName)
|
output.outputFile = new File(outputFile.parent, fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
swagger_annotations_version = "1.5.0"
|
swagger_annotations_version = "1.5.0"
|
||||||
gson_version = "2.3.1"
|
gson_version = "2.3.1"
|
||||||
httpclient_version = "4.3.3"
|
httpclient_version = "4.3.3"
|
||||||
junit_version = "4.8.1"
|
junit_version = "4.8.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||||
compile "com.google.code.gson:gson:$gson_version"
|
compile "com.google.code.gson:gson:$gson_version"
|
||||||
compile "org.apache.httpcomponents:httpcore:$httpclient_version"
|
compile "org.apache.httpcomponents:httpcore:$httpclient_version"
|
||||||
compile "org.apache.httpcomponents:httpclient:$httpclient_version"
|
compile "org.apache.httpcomponents:httpclient:$httpclient_version"
|
||||||
compile ("org.apache.httpcomponents:httpcore:$httpclient_version") {
|
compile ("org.apache.httpcomponents:httpcore:$httpclient_version") {
|
||||||
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
||||||
}
|
}
|
||||||
compile ("org.apache.httpcomponents:httpmime:$httpclient_version") {
|
compile ("org.apache.httpcomponents:httpmime:$httpclient_version") {
|
||||||
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
||||||
}
|
}
|
||||||
testCompile "junit:junit:$junit_version"
|
testCompile "junit:junit:$junit_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.libraryVariants.all { variant ->
|
android.libraryVariants.all { variant ->
|
||||||
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
||||||
task.description = "Create jar artifact for ${variant.name}"
|
task.description = "Create jar artifact for ${variant.name}"
|
||||||
task.dependsOn variant.javaCompile
|
task.dependsOn variant.javaCompile
|
||||||
task.from variant.javaCompile.destinationDir
|
task.from variant.javaCompile.destinationDir
|
||||||
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
|
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
|
||||||
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
|
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
|
||||||
artifacts.add('archives', task);
|
artifacts.add('archives', task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#useAndroidMavenGradlePlugin}}
|
{{#useAndroidMavenGradlePlugin}}
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
from android.sourceSets.main.java.srcDirs
|
from android.sourceSets.main.java.srcDirs
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
archives sourcesJar
|
archives sourcesJar
|
||||||
}
|
}
|
||||||
{{/useAndroidMavenGradlePlugin}}
|
{{/useAndroidMavenGradlePlugin}}
|
@ -3,14 +3,14 @@ package {{invokerPackage}};
|
|||||||
import org.apache.http.client.methods.*;
|
import org.apache.http.client.methods.*;
|
||||||
|
|
||||||
public class HttpPatch extends HttpPost {
|
public class HttpPatch extends HttpPost {
|
||||||
public static final String METHOD_PATCH = "PATCH";
|
public static final String METHOD_PATCH = "PATCH";
|
||||||
|
|
||||||
public HttpPatch(final String url) {
|
public HttpPatch(final String url) {
|
||||||
super(url);
|
super(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMethod() {
|
public String getMethod() {
|
||||||
return METHOD_PATCH;
|
return METHOD_PATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,55 +8,48 @@ import java.util.List;
|
|||||||
import {{modelPackage}}.*;
|
import {{modelPackage}}.*;
|
||||||
|
|
||||||
public class JsonUtil {
|
public class JsonUtil {
|
||||||
public static GsonBuilder gsonBuilder;
|
public static GsonBuilder gsonBuilder;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
gsonBuilder = new GsonBuilder();
|
gsonBuilder = new GsonBuilder();
|
||||||
gsonBuilder.serializeNulls();
|
gsonBuilder.serializeNulls();
|
||||||
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Gson getGson() {
|
public static Gson getGson() {
|
||||||
return gsonBuilder.create();
|
return gsonBuilder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String serialize(Object obj){
|
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 <T> T deserializeToObject(String jsonString, Class cls){
|
||||||
|
return getGson().fromJson(jsonString, getTypeForDeserialization(cls));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type getListTypeForDeserialization(Class cls) {
|
||||||
|
String className = cls.getSimpleName();
|
||||||
|
{{#models}}{{#model}}
|
||||||
|
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||||
|
return new TypeToken<List<{{classname}}>>(){}.getType();
|
||||||
}
|
}
|
||||||
|
{{/model}}{{/models}}
|
||||||
|
return new TypeToken<List<Object>>(){}.getType();
|
||||||
|
}
|
||||||
|
|
||||||
public static
|
public static Type getTypeForDeserialization(Class cls) {
|
||||||
<T> T deserializeToObject(String jsonString, Class cls){
|
String className = cls.getSimpleName();
|
||||||
return getGson().fromJson(jsonString, getTypeForDeserialization(cls));
|
{{#models}}{{#model}}
|
||||||
}
|
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||||
|
return new TypeToken<{{classname}}>(){}.getType();
|
||||||
|
}
|
||||||
|
{{/model}}{{/models}}
|
||||||
|
return new TypeToken<Object>(){}.getType();
|
||||||
|
}
|
||||||
|
|
||||||
public static Type getListTypeForDeserialization(Class cls) {
|
};
|
||||||
String className = cls.getSimpleName();
|
|
||||||
{{#models}}{{#model}}
|
|
||||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
|
||||||
return new TypeToken
|
|
||||||
<List
|
|
||||||
<{{classname}}>>(){}.getType();
|
|
||||||
}
|
|
||||||
{{/model}}{{/models}}
|
|
||||||
return new TypeToken
|
|
||||||
<List
|
|
||||||
<Object>>(){}.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Type getTypeForDeserialization(Class cls) {
|
|
||||||
String className = cls.getSimpleName();
|
|
||||||
{{#models}}{{#model}}
|
|
||||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
|
||||||
return new TypeToken<{{classname}}>(){}.getType();
|
|
||||||
}
|
|
||||||
{{/model}}{{/models}}
|
|
||||||
return new TypeToken
|
|
||||||
<Object>(){}.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<manifest package="{{invokerPackage}}">
|
<manifest package="{{invokerPackage}}">
|
||||||
<application/>
|
<application />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -7,46 +7,46 @@ import io.swagger.annotations.*;
|
|||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
{{#models}}
|
{{#models}}
|
||||||
|
|
||||||
{{#model}}{{#description}}
|
{{#model}}{{#description}}
|
||||||
/**
|
/**
|
||||||
* {{description}}
|
* {{description}}
|
||||||
**/{{/description}}
|
**/{{/description}}
|
||||||
@ApiModel(description = "{{{description}}}")
|
@ApiModel(description = "{{{description}}}")
|
||||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||||
{{#vars}}{{#isEnum}}
|
{{#vars}}{{#isEnum}}
|
||||||
public enum {{datatypeWithEnum}} {
|
public enum {{datatypeWithEnum}} {
|
||||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||||
};
|
};
|
||||||
@SerializedName("{{baseName}}")
|
@SerializedName("{{baseName}}")
|
||||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||||
@SerializedName("{{baseName}}")
|
@SerializedName("{{baseName}}")
|
||||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
/**{{#description}}
|
/**{{#description}}
|
||||||
* {{{description}}}{{/description}}{{#minimum}}
|
* {{{description}}}{{/description}}{{#minimum}}
|
||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||||
return {{name}};
|
return {{name}};
|
||||||
}
|
}
|
||||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||||
this.{{name}} = {{name}};
|
this.{{name}} = {{name}};
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("class {{classname}} {\n");
|
sb.append("class {{classname}} {\n");
|
||||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||||
{{/vars}}sb.append("}\n");
|
{{/vars}}sb.append("}\n");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
||||||
|
@ -1,158 +1,155 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>{{groupId}}</groupId>
|
<groupId>{{groupId}}</groupId>
|
||||||
<artifactId>{{artifactId}}</artifactId>
|
<artifactId>{{artifactId}}</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>{{artifactId}}</name>
|
<name>{{artifactId}}</name>
|
||||||
<version>{{artifactVersion}}</version>
|
<version>{{artifactVersion}}</version>
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
|
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
|
||||||
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
|
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
|
||||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||||
</scm>
|
</scm>
|
||||||
<prerequisites>
|
<prerequisites>
|
||||||
<maven>2.2.0</maven>
|
<maven>2.2.0</maven>
|
||||||
</prerequisites>
|
</prerequisites>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.12</version>
|
<version>2.12</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<systemProperties>
|
<systemProperties>
|
||||||
<property>
|
<property>
|
||||||
<name>loggerPath</name>
|
<name>loggerPath</name>
|
||||||
<value>conf/log4j.properties</value>
|
<value>conf/log4j.properties</value>
|
||||||
</property>
|
</property>
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||||
<parallel>methods</parallel>
|
<parallel>methods</parallel>
|
||||||
<forkMode>pertest</forkMode>
|
<forkMode>pertest</forkMode>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>copy-dependencies</goal>
|
<goal>copy-dependencies</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- attach test jar -->
|
<!-- attach test jar -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>2.2</version>
|
<version>2.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar</goal>
|
<goal>jar</goal>
|
||||||
<goal>test-jar</goal>
|
<goal>test-jar</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>add_sources</id>
|
<id>add_sources</id>
|
||||||
<phase>generate-sources</phase>
|
<phase>generate-sources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>add-source</goal>
|
<goal>add-source</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>
|
<source>src/main/java</source>
|
||||||
src/main/java</source>
|
</sources>
|
||||||
</sources>
|
</configuration>
|
||||||
</configuration>
|
</execution>
|
||||||
</execution>
|
<execution>
|
||||||
<execution>
|
<id>add_test_sources</id>
|
||||||
<id>add_test_sources</id>
|
<phase>generate-test-sources</phase>
|
||||||
<phase>generate-test-sources</phase>
|
<goals>
|
||||||
<goals>
|
<goal>add-test-source</goal>
|
||||||
<goal>add-test-source</goal>
|
</goals>
|
||||||
</goals>
|
<configuration>
|
||||||
<configuration>
|
<sources>
|
||||||
<sources>
|
<source>src/test/java</source>
|
||||||
<source>
|
</sources>
|
||||||
src/test/java</source>
|
</configuration>
|
||||||
</sources>
|
</execution>
|
||||||
</configuration>
|
</executions>
|
||||||
</execution>
|
</plugin>
|
||||||
</executions>
|
<plugin>
|
||||||
</plugin>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<plugin>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<version>2.3.2</version>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<configuration>
|
||||||
<version>2.3.2</version>
|
<source>1.6</source>
|
||||||
<configuration>
|
<target>1.6</target>
|
||||||
<source>
|
</configuration>
|
||||||
1.6</source>
|
</plugin>
|
||||||
<target>1.6</target>
|
</plugins>
|
||||||
</configuration>
|
</build>
|
||||||
</plugin>
|
<dependencies>
|
||||||
</plugins>
|
<dependency>
|
||||||
</build>
|
<groupId>io.swagger</groupId>
|
||||||
<dependencies>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
<dependency>
|
<version>${swagger-annotations-version}</version>
|
||||||
<groupId>io.swagger</groupId>
|
</dependency>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<dependency>
|
||||||
<version>${swagger-annotations-version}</version>
|
<groupId>com.google.code.gson</groupId>
|
||||||
</dependency>
|
<artifactId>gson</artifactId>
|
||||||
<dependency>
|
<version>${gson-version}</version>
|
||||||
<groupId>com.google.code.gson</groupId>
|
</dependency>
|
||||||
<artifactId>gson</artifactId>
|
<dependency>
|
||||||
<version>${gson-version}</version>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
</dependency>
|
<artifactId>httpclient</artifactId>
|
||||||
<dependency>
|
<version>${httpclient-version}</version>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<scope>compile</scope>
|
||||||
<artifactId>httpclient</artifactId>
|
</dependency>
|
||||||
<version>${httpclient-version}</version>
|
<dependency>
|
||||||
<scope>compile</scope>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
</dependency>
|
<artifactId>httpmime</artifactId>
|
||||||
<dependency>
|
<version>${httpclient-version}</version>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<scope>compile</scope>
|
||||||
<artifactId>httpmime</artifactId>
|
</dependency>
|
||||||
<version>${httpclient-version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test dependencies -->
|
<!-- test dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>${junit-version}</version>
|
<version>${junit-version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype-snapshots</id>
|
<id>sonatype-snapshots</id>
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||||
<gson-version>2.3.1</gson-version>
|
<gson-version>2.3.1</gson-version>
|
||||||
<junit-version>4.8.1</junit-version>
|
<junit-version>4.8.1</junit-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
<junit-version>4.8.1</junit-version>
|
<junit-version>4.8.1</junit-version>
|
||||||
<httpclient-version>4.3.6</httpclient-version>
|
<httpclient-version>4.3.6</httpclient-version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
Loading…
x
Reference in New Issue
Block a user