From 180d48e89dd9f9544774ce7eb343a4f9b4c300dc Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 9 Jun 2015 13:08:32 +0800 Subject: [PATCH] rollback java template --- .../main/resources/Java/ApiClient.mustache | 854 +++++++++--------- .../resources/Java/Configuration.mustache | 30 +- .../src/main/resources/Java/JsonUtil.mustache | 20 +- .../main/resources/Java/StringUtil.mustache | 70 +- .../src/main/resources/Java/api.mustache | 172 ++-- .../main/resources/Java/apiException.mustache | 72 +- .../resources/Java/auth/ApiKeyAuth.mustache | 82 +- .../Java/auth/Authentication.mustache | 6 +- .../Java/auth/HttpBasicAuth.mustache | 48 +- .../main/resources/Java/auth/OAuth.mustache | 10 +- .../src/main/resources/Java/model.mustache | 64 +- .../src/main/resources/Java/pom.mustache | 325 ++++--- 12 files changed, 857 insertions(+), 896 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index cab3d3f2618..352401ba0d8 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -40,482 +40,468 @@ import {{invokerPackage}}.auth.ApiKeyAuth; import {{invokerPackage}}.auth.OAuth; public class ApiClient { -private Map - hostMap = new HashMap -(); -private Map - defaultHeaderMap = new HashMap -(); -private boolean debugging = false; -private String basePath = "{{basePath}}"; + private Map hostMap = new HashMap(); + private Map defaultHeaderMap = new HashMap(); + private boolean debugging = false; + private String basePath = "{{basePath}}"; -private Map - authentications; + private Map authentications; -private DateFormat dateFormat; + private DateFormat dateFormat; -public ApiClient() { -// Use ISO 8601 format for date and datetime. -// See https://en.wikipedia.org/wiki/ISO_8601 -this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + public ApiClient() { + // Use ISO 8601 format for date and datetime. + // See https://en.wikipedia.org/wiki/ISO_8601 + this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); -// Use UTC as the default time zone. -this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + // Use UTC as the default time zone. + this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); -// Set default User-Agent. -setUserAgent("Java-Swagger"); + // Set default User-Agent. + setUserAgent("Java-Swagger"); -// Setup authentications (key: authentication name, value: authentication). -authentications = new HashMap -();{{#authMethods}}{{#isBasic}} + // Setup authentications (key: authentication name, value: authentication). + authentications = new HashMap();{{#authMethods}}{{#isBasic}} authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}} authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}} authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}} -// Prevent the authentications from being modified. -authentications = Collections.unmodifiableMap(authentications); -} + // Prevent the authentications from being modified. + authentications = Collections.unmodifiableMap(authentications); + } -public String getBasePath() { -return basePath; -} + public String getBasePath() { + return basePath; + } -public ApiClient setBasePath(String basePath) { -this.basePath = basePath; -return this; -} + public ApiClient setBasePath(String basePath) { + this.basePath = basePath; + return this; + } -/** -* Get authentications (key: authentication name, value: authentication). -*/ -public Map - getAuthentications() { -return authentications; -} + /** + * Get authentications (key: authentication name, value: authentication). + */ + public Map getAuthentications() { + return authentications; + } -/** -* Get authentication for the given name. -* -* @param authName The authentication name -* @return The authentication, null if not found -*/ -public Authentication getAuthentication(String authName) { -return authentications.get(authName); -} + /** + * Get authentication for the given name. + * + * @param authName The authentication name + * @return The authentication, null if not found + */ + public Authentication getAuthentication(String authName) { + return authentications.get(authName); + } -/** -* Helper method to set username for the first HTTP basic authentication. -*/ -public void setUsername(String username) { -for (Authentication auth : authentications.values()) { -if (auth instanceof HttpBasicAuth) { -((HttpBasicAuth) auth).setUsername(username); -return; -} -} -throw new RuntimeException("No HTTP basic authentication configured!"); -} + /** + * Helper method to set username for the first HTTP basic authentication. + */ + public void setUsername(String username) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setUsername(username); + return; + } + } + throw new RuntimeException("No HTTP basic authentication configured!"); + } -/** -* Helper method to set password for the first HTTP basic authentication. -*/ -public void setPassword(String password) { -for (Authentication auth : authentications.values()) { -if (auth instanceof HttpBasicAuth) { -((HttpBasicAuth) auth).setPassword(password); -return; -} -} -throw new RuntimeException("No HTTP basic authentication configured!"); -} + /** + * Helper method to set password for the first HTTP basic authentication. + */ + public void setPassword(String password) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setPassword(password); + return; + } + } + throw new RuntimeException("No HTTP basic authentication configured!"); + } -/** -* Helper method to set API key value for the first API key authentication. -*/ -public void setApiKey(String apiKey) { -for (Authentication auth : authentications.values()) { -if (auth instanceof ApiKeyAuth) { -((ApiKeyAuth) auth).setApiKey(apiKey); -return; -} -} -throw new RuntimeException("No API key authentication configured!"); -} + /** + * Helper method to set API key value for the first API key authentication. + */ + public void setApiKey(String apiKey) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKey(apiKey); + return; + } + } + throw new RuntimeException("No API key authentication configured!"); + } -/** -* Helper method to set API key prefix for the first API key authentication. -*/ -public void setApiKeyPrefix(String apiKeyPrefix) { -for (Authentication auth : authentications.values()) { -if (auth instanceof ApiKeyAuth) { -((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); -return; -} -} -throw new RuntimeException("No API key authentication configured!"); -} + /** + * Helper method to set API key prefix for the first API key authentication. + */ + public void setApiKeyPrefix(String apiKeyPrefix) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); + return; + } + } + throw new RuntimeException("No API key authentication configured!"); + } -/** -* Set the User-Agent header's value (by adding to the default header map). -*/ -public ApiClient setUserAgent(String userAgent) { -addDefaultHeader("User-Agent", userAgent); -return this; -} + /** + * Set the User-Agent header's value (by adding to the default header map). + */ + public ApiClient setUserAgent(String userAgent) { + addDefaultHeader("User-Agent", userAgent); + return this; + } -/** -* Add a default header. -* -* @param key The header's key -* @param value The header's value -*/ -public ApiClient addDefaultHeader(String key, String value) { -defaultHeaderMap.put(key, value); -return this; -} + /** + * Add a default header. + * + * @param key The header's key + * @param value The header's value + */ + public ApiClient addDefaultHeader(String key, String value) { + defaultHeaderMap.put(key, value); + return this; + } -/** -* Check that whether debugging is enabled for this API client. -*/ -public boolean isDebugging() { -return debugging; -} + /** + * Check that whether debugging is enabled for this API client. + */ + public boolean isDebugging() { + return debugging; + } -/** -* Enable/disable debugging for this API client. -* -* @param debugging To enable (true) or disable (false) debugging -*/ -public ApiClient setDebugging(boolean debugging) { -this.debugging = debugging; -return this; -} + /** + * Enable/disable debugging for this API client. + * + * @param debugging To enable (true) or disable (false) debugging + */ + public ApiClient setDebugging(boolean debugging) { + this.debugging = debugging; + return this; + } -/** -* Get the date format used to parse/format date parameters. -*/ -public DateFormat getDateFormat() { -return dateFormat; -} + /** + * Get the date format used to parse/format date parameters. + */ + public DateFormat getDateFormat() { + return dateFormat; + } -/** -* Set the date format used to parse/format date parameters. -*/ -public ApiClient getDateFormat(DateFormat dateFormat) { -this.dateFormat = dateFormat; -return this; -} + /** + * Set the date format used to parse/format date parameters. + */ + public ApiClient getDateFormat(DateFormat dateFormat) { + this.dateFormat = dateFormat; + return this; + } -/** -* Parse the given string into Date object. -*/ -public Date parseDate(String str) { -try { -return dateFormat.parse(str); -} catch (java.text.ParseException e) { -throw new RuntimeException(e); -} -} + /** + * Parse the given string into Date object. + */ + public Date parseDate(String str) { + try { + return dateFormat.parse(str); + } catch (java.text.ParseException e) { + throw new RuntimeException(e); + } + } -/** -* Format the given Date object into string. -*/ -public String formatDate(Date date) { -return dateFormat.format(date); -} + /** + * Format the given Date object into string. + */ + public String formatDate(Date date) { + return dateFormat.format(date); + } -/** -* Format the given parameter object into string. -*/ -public String parameterToString(Object param) { -if (param == null) { -return ""; -} else if (param instanceof Date) { -return formatDate((Date) param); -} else if (param instanceof Collection) { -StringBuilder b = new StringBuilder(); -for(Object o : (Collection)param) { -if(b.length() > 0) { -b.append(","); -} -b.append(String.valueOf(o)); -} -return b.toString(); -} else { -return String.valueOf(param); -} -} + /** + * Format the given parameter object into string. + */ + public String parameterToString(Object param) { + if (param == null) { + return ""; + } else if (param instanceof Date) { + return formatDate((Date) param); + } else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for(Object o : (Collection)param) { + if(b.length() > 0) { + b.append(","); + } + b.append(String.valueOf(o)); + } + return b.toString(); + } else { + return String.valueOf(param); + } + } -/** -* Select the Accept header's value from the given accepts array: -* if JSON exists in the given array, use it; -* otherwise use all of them (joining into a string) -* -* @param accepts The accepts array to select from -* @return The Accept header to use. If the given array is empty, -* null will be returned (not to set the Accept header explicitly). -*/ -public String selectHeaderAccept(String[] accepts) { -if (accepts.length == 0) return null; -if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json"; -return StringUtil.join(accepts, ","); -} + /** + * Select the Accept header's value from the given accepts array: + * if JSON exists in the given array, use it; + * otherwise use all of them (joining into a string) + * + * @param accepts The accepts array to select from + * @return The Accept header to use. If the given array is empty, + * null will be returned (not to set the Accept header explicitly). + */ + public String selectHeaderAccept(String[] accepts) { + if (accepts.length == 0) return null; + if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json"; + return StringUtil.join(accepts, ","); + } -/** -* Select the Content-Type header's value from the given array: -* if JSON exists in the given array, use it; -* otherwise use the first one of the array. -* -* @param contentTypes The Content-Type array to select from -* @return The Content-Type header to use. If the given array is empty, -* JSON will be used. -*/ -public String selectHeaderContentType(String[] contentTypes) { -if (contentTypes.length == 0) return "application/json"; -if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json"; -return contentTypes[0]; -} + /** + * Select the Content-Type header's value from the given array: + * if JSON exists in the given array, use it; + * otherwise use the first one of the array. + * + * @param contentTypes The Content-Type array to select from + * @return The Content-Type header to use. If the given array is empty, + * JSON will be used. + */ + public String selectHeaderContentType(String[] contentTypes) { + if (contentTypes.length == 0) return "application/json"; + if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json"; + return contentTypes[0]; + } -/** -* Escape the given string to be used as URL query value. -*/ -public String escapeString(String str) { -try { -return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); -} catch (UnsupportedEncodingException e) { -return str; -} -} + /** + * Escape the given string to be used as URL query value. + */ + public String escapeString(String str) { + try { + return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); + } catch (UnsupportedEncodingException e) { + return str; + } + } -/** -* Deserialize the given JSON string to Java object. -* -* @param json The JSON string -* @param containerType The container type, one of "list", "array" or "" -* @param cls The type of the Java object -* @return The deserialized Java object -*/ -public Object deserialize(String json, String containerType, Class cls) throws ApiException { -if(null != containerType) { -containerType = containerType.toLowerCase(); -} -try{ -if("list".equals(containerType) || "array".equals(containerType)) { -JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls); -List response = (List) JsonUtil.getJsonMapper().readValue(json, typeInfo); -return response; -} -else if(String.class.equals(cls)) { -if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) -return json.substring(1, json.length() - 2); -else -return json; -} -else { -return JsonUtil.getJsonMapper().readValue(json, cls); -} -} -catch (IOException e) { -throw new ApiException(500, e.getMessage(), null, json); -} -} + /** + * Deserialize the given JSON string to Java object. + * + * @param json The JSON string + * @param containerType The container type, one of "list", "array" or "" + * @param cls The type of the Java object + * @return The deserialized Java object + */ + public Object deserialize(String json, String containerType, Class cls) throws ApiException { + if(null != containerType) { + containerType = containerType.toLowerCase(); + } + try{ + if("list".equals(containerType) || "array".equals(containerType)) { + JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls); + List response = (List) JsonUtil.getJsonMapper().readValue(json, typeInfo); + return response; + } + else if(String.class.equals(cls)) { + if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) + return json.substring(1, json.length() - 2); + else + return json; + } + else { + return JsonUtil.getJsonMapper().readValue(json, cls); + } + } + catch (IOException e) { + throw new ApiException(500, e.getMessage(), null, json); + } + } -/** -* Serialize the given Java object into JSON string. -*/ -public String serialize(Object obj) throws ApiException { -try { -if (obj != null) -return JsonUtil.getJsonMapper().writeValueAsString(obj); -else -return null; -} -catch (Exception e) { -throw new ApiException(500, e.getMessage()); -} -} + /** + * Serialize the given Java object into JSON string. + */ + public String serialize(Object obj) throws ApiException { + try { + if (obj != null) + return JsonUtil.getJsonMapper().writeValueAsString(obj); + else + return null; + } + catch (Exception e) { + throw new ApiException(500, e.getMessage()); + } + } -/** -* Invoke API by sending HTTP request with the given options. -* -* @param path The sub-path of the HTTP URL -* @param method The request method, one of "GET", "POST", "PUT", and "DELETE" -* @param queryParams The query parameters -* @param body The request body object -* @param headerParams The header parameters -* @param formParams The form parameters -* @param accept The request's Accept header -* @param contentType The request's Content-Type header -* @param authNames The authentications to apply -* @return The response body in type of string -*/ -public String invokeAPI(String path, String method, Map - queryParams, Object body, Map - headerParams, Map - formParams, String accept, String contentType, String[] authNames) throws ApiException { -updateParamsForAuth(authNames, queryParams, headerParams); + /** + * Invoke API by sending HTTP request with the given options. + * + * @param path The sub-path of the HTTP URL + * @param method The request method, one of "GET", "POST", "PUT", and "DELETE" + * @param queryParams The query parameters + * @param body The request body object + * @param headerParams The header parameters + * @param formParams The form parameters + * @param accept The request's Accept header + * @param contentType The request's Content-Type header + * @param authNames The authentications to apply + * @return The response body in type of string + */ + public String invokeAPI(String path, String method, Map queryParams, Object body, Map headerParams, Map formParams, String accept, String contentType, String[] authNames) throws ApiException { + updateParamsForAuth(authNames, queryParams, headerParams); -Client client = getClient(); + Client client = getClient(); -StringBuilder b = new StringBuilder(); -for(String key : queryParams.keySet()) { -String value = queryParams.get(key); -if (value != null){ -if(b.toString().length() == 0) -b.append("?"); -else -b.append("&"); -b.append(escapeString(key)).append("=").append(escapeString(value)); -} -} -String querystring = b.toString(); + StringBuilder b = new StringBuilder(); + for(String key : queryParams.keySet()) { + String value = queryParams.get(key); + if (value != null){ + if(b.toString().length() == 0) + b.append("?"); + else + b.append("&"); + b.append(escapeString(key)).append("=").append(escapeString(value)); + } + } + String querystring = b.toString(); -Builder builder; -if (accept == null) -builder = client.resource(basePath + path + querystring).getRequestBuilder(); -else -builder = client.resource(basePath + path + querystring).accept(accept); + Builder builder; + if (accept == null) + builder = client.resource(basePath + path + querystring).getRequestBuilder(); + else + builder = client.resource(basePath + path + querystring).accept(accept); -for(String key : headerParams.keySet()) { -builder = builder.header(key, headerParams.get(key)); -} -for(String key : defaultHeaderMap.keySet()) { -if(!headerParams.containsKey(key)) { -builder = builder.header(key, defaultHeaderMap.get(key)); -} -} + for(String key : headerParams.keySet()) { + builder = builder.header(key, headerParams.get(key)); + } + for(String key : defaultHeaderMap.keySet()) { + if(!headerParams.containsKey(key)) { + builder = builder.header(key, defaultHeaderMap.get(key)); + } + } -ClientResponse response = null; + ClientResponse response = null; -if("GET".equals(method)) { -response = (ClientResponse) builder.get(ClientResponse.class); -} -else if ("POST".equals(method)) { -if (contentType.startsWith("application/x-www-form-urlencoded")) { -String encodedFormParams = this -.getXWWWFormUrlencodedParams(formParams); -response = builder.type(contentType).post(ClientResponse.class, -encodedFormParams); -} else if (body == null) { -response = builder.post(ClientResponse.class, null); -} else if(body instanceof FormDataMultiPart) { -response = builder.type(contentType).post(ClientResponse.class, body); -} -else -response = builder.type(contentType).post(ClientResponse.class, serialize(body)); -} -else if ("PUT".equals(method)) { -if ("application/x-www-form-urlencoded".equals(contentType)) { -String encodedFormParams = this -.getXWWWFormUrlencodedParams(formParams); -response = builder.type(contentType).put(ClientResponse.class, -encodedFormParams); -} else if(body == null) { -response = builder.put(ClientResponse.class, serialize(body)); -} else { -response = builder.type(contentType).put(ClientResponse.class, serialize(body)); -} -} -else if ("DELETE".equals(method)) { -if ("application/x-www-form-urlencoded".equals(contentType)) { -String encodedFormParams = this -.getXWWWFormUrlencodedParams(formParams); -response = builder.type(contentType).delete(ClientResponse.class, -encodedFormParams); -} else if(body == null) { -response = builder.delete(ClientResponse.class); -} else { -response = builder.type(contentType).delete(ClientResponse.class, serialize(body)); -} -} -else { -throw new ApiException(500, "unknown method type " + method); -} + if("GET".equals(method)) { + response = (ClientResponse) builder.get(ClientResponse.class); + } + else if ("POST".equals(method)) { + if (contentType.startsWith("application/x-www-form-urlencoded")) { + String encodedFormParams = this + .getXWWWFormUrlencodedParams(formParams); + response = builder.type(contentType).post(ClientResponse.class, + encodedFormParams); + } else if (body == null) { + response = builder.post(ClientResponse.class, null); + } else if(body instanceof FormDataMultiPart) { + response = builder.type(contentType).post(ClientResponse.class, body); + } + else + response = builder.type(contentType).post(ClientResponse.class, serialize(body)); + } + else if ("PUT".equals(method)) { + if ("application/x-www-form-urlencoded".equals(contentType)) { + String encodedFormParams = this + .getXWWWFormUrlencodedParams(formParams); + response = builder.type(contentType).put(ClientResponse.class, + encodedFormParams); + } else if(body == null) { + response = builder.put(ClientResponse.class, serialize(body)); + } else { + response = builder.type(contentType).put(ClientResponse.class, serialize(body)); + } + } + else if ("DELETE".equals(method)) { + if ("application/x-www-form-urlencoded".equals(contentType)) { + String encodedFormParams = this + .getXWWWFormUrlencodedParams(formParams); + response = builder.type(contentType).delete(ClientResponse.class, + encodedFormParams); + } else if(body == null) { + response = builder.delete(ClientResponse.class); + } else { + response = builder.type(contentType).delete(ClientResponse.class, serialize(body)); + } + } + else { + throw new ApiException(500, "unknown method type " + method); + } -if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { -return null; -} -else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { -if(response.hasEntity()) { -return (String) response.getEntity(String.class); -} -else { -return ""; -} -} -else { -String message = "error"; -String respBody = null; -if(response.hasEntity()) { -try{ -respBody = String.valueOf(response.getEntity(String.class)); -message = respBody; -} -catch (RuntimeException e) { -// e.printStackTrace(); -} -} -throw new ApiException( -response.getClientResponseStatus().getStatusCode(), -message, -response.getHeaders(), -respBody); -} -} + if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { + return null; + } + else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { + if(response.hasEntity()) { + return (String) response.getEntity(String.class); + } + else { + return ""; + } + } + else { + String message = "error"; + String respBody = null; + if(response.hasEntity()) { + try{ + respBody = String.valueOf(response.getEntity(String.class)); + message = respBody; + } + catch (RuntimeException e) { + // e.printStackTrace(); + } + } + throw new ApiException( + response.getClientResponseStatus().getStatusCode(), + message, + response.getHeaders(), + respBody); + } + } -/** -* Update query and header parameters based on authentication settings. -* -* @param authNames The authentications to apply -*/ -private void updateParamsForAuth(String[] authNames, Map - queryParams, Map - headerParams) { -for (String authName : authNames) { -Authentication auth = authentications.get(authName); -if (auth == null) throw new RuntimeException("Authentication undefined: " + authName); -auth.applyToParams(queryParams, headerParams); -} -} + /** + * Update query and header parameters based on authentication settings. + * + * @param authNames The authentications to apply + */ + private void updateParamsForAuth(String[] authNames, Map queryParams, Map headerParams) { + for (String authName : authNames) { + Authentication auth = authentications.get(authName); + if (auth == null) throw new RuntimeException("Authentication undefined: " + authName); + auth.applyToParams(queryParams, headerParams); + } + } -/** -* Encode the given form parameters as request body. -*/ -private String getXWWWFormUrlencodedParams(Map - formParams) { -StringBuilder formParamBuilder = new StringBuilder(); + /** + * Encode the given form parameters as request body. + */ + private String getXWWWFormUrlencodedParams(Map formParams) { + StringBuilder formParamBuilder = new StringBuilder(); -for (Entry - param : formParams.entrySet()) { -String keyStr = parameterToString(param.getKey()); -String valueStr = parameterToString(param.getValue()); + for (Entry param : formParams.entrySet()) { + String keyStr = parameterToString(param.getKey()); + String valueStr = parameterToString(param.getValue()); -try { -formParamBuilder.append(URLEncoder.encode(keyStr, "utf8")) -.append("=") -.append(URLEncoder.encode(valueStr, "utf8")); -formParamBuilder.append("&"); -} catch (UnsupportedEncodingException e) { -// move on to next -} -} -String encodedFormParams = formParamBuilder.toString(); -if (encodedFormParams.endsWith("&")) { -encodedFormParams = encodedFormParams.substring(0, -encodedFormParams.length() - 1); -} -return encodedFormParams; -} + try { + formParamBuilder.append(URLEncoder.encode(keyStr, "utf8")) + .append("=") + .append(URLEncoder.encode(valueStr, "utf8")); + formParamBuilder.append("&"); + } catch (UnsupportedEncodingException e) { + // move on to next + } + } + String encodedFormParams = formParamBuilder.toString(); + if (encodedFormParams.endsWith("&")) { + encodedFormParams = encodedFormParams.substring(0, + encodedFormParams.length() - 1); + } + return encodedFormParams; + } -/** -* Get an existing client or create a new client to handle HTTP request. -*/ -private Client getClient() { -if(!hostMap.containsKey(basePath)) { -Client client = Client.create(); -if (debugging) -client.addFilter(new LoggingFilter()); -hostMap.put(basePath, client); -} -return hostMap.get(basePath); -} + /** + * Get an existing client or create a new client to handle HTTP request. + */ + private Client getClient() { + if(!hostMap.containsKey(basePath)) { + Client client = Client.create(); + if (debugging) + client.addFilter(new LoggingFilter()); + hostMap.put(basePath, client); + } + return hostMap.get(basePath); + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/Configuration.mustache b/modules/swagger-codegen/src/main/resources/Java/Configuration.mustache index 473840fc0b0..e936b423a91 100644 --- a/modules/swagger-codegen/src/main/resources/Java/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/Configuration.mustache @@ -1,21 +1,21 @@ package {{invokerPackage}}; public class Configuration { -private static ApiClient defaultApiClient = new ApiClient(); + private static ApiClient defaultApiClient = new ApiClient(); -/** -* Get the default API client, which would be used when creating API -* instances without providing an API client. -*/ -public static ApiClient getDefaultApiClient() { -return defaultApiClient; -} + /** + * Get the default API client, which would be used when creating API + * instances without providing an API client. + */ + public static ApiClient getDefaultApiClient() { + return defaultApiClient; + } -/** -* Set the default API client, which would be used when creating API -* instances without providing an API client. -*/ -public static void setDefaultApiClient(ApiClient apiClient) { -defaultApiClient = apiClient; -} + /** + * Set the default API client, which would be used when creating API + * instances without providing an API client. + */ + public static void setDefaultApiClient(ApiClient apiClient) { + defaultApiClient = apiClient; + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/JsonUtil.mustache b/modules/swagger-codegen/src/main/resources/Java/JsonUtil.mustache index 1cba673ef29..29d5f55ecee 100644 --- a/modules/swagger-codegen/src/main/resources/Java/JsonUtil.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/JsonUtil.mustache @@ -8,16 +8,16 @@ import com.fasterxml.jackson.core.JsonGenerator.Feature; import com.fasterxml.jackson.datatype.joda.*; public class JsonUtil { -public static ObjectMapper mapper; + public static ObjectMapper mapper; -static { -mapper = new ObjectMapper(); -mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); -mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); -mapper.registerModule(new JodaModule()); -} + static { + mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper.registerModule(new JodaModule()); + } -public static ObjectMapper getJsonMapper() { -return mapper; -} + public static ObjectMapper getJsonMapper() { + return mapper; + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/StringUtil.mustache b/modules/swagger-codegen/src/main/resources/Java/StringUtil.mustache index 0add94b988d..035d6739dce 100644 --- a/modules/swagger-codegen/src/main/resources/Java/StringUtil.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/StringUtil.mustache @@ -1,41 +1,41 @@ package {{invokerPackage}}; public class StringUtil { -/** -* Check if the given array contains the given value (with case-insensitive comparison). -* -* @param array The array -* @param value The value to search -* @return true if the array contains the value -*/ -public static boolean containsIgnoreCase(String[] array, String value) { -for (String str : array) { -if (value == null && str == null) return true; -if (value != null && value.equalsIgnoreCase(str)) return true; -} -return false; -} + /** + * Check if the given array contains the given value (with case-insensitive comparison). + * + * @param array The array + * @param value The value to search + * @return true if the array contains the value + */ + public static boolean containsIgnoreCase(String[] array, String value) { + for (String str : array) { + if (value == null && str == null) return true; + if (value != null && value.equalsIgnoreCase(str)) return true; + } + return false; + } -/** -* Join an array of strings with the given separator. -*

- * Note: This might be replaced by utility method from commons-lang or guava someday - * if one of those libraries is added as dependency. - *

-* -* @param array The array of strings -* @param separator The separator -* @return the resulting string -*/ -public static String join(String[] array, String separator) { -int len = array.length; -if (len == 0) return ""; + /** + * Join an array of strings with the given separator. + *

+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *

+ * + * @param array The array of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(String[] array, String separator) { + int len = array.length; + if (len == 0) return ""; -StringBuilder out = new StringBuilder(); -out.append(array[0]); -for (int i = 1; i < len; i++) { -out.append(separator).append(array[i]); -} -return out.toString(); -} + StringBuilder out = new StringBuilder(); + out.append(array[0]); + for (int i = 1; i < len; i++) { + out.append(separator).append(array[i]); + } + return out.toString(); + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index bcc9c5b0aa1..63357afd896 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -21,111 +21,105 @@ import java.util.Map; import java.util.HashMap; {{#operations}} - public class {{classname}} { - private ApiClient apiClient; +public class {{classname}} { + private ApiClient apiClient; - public {{classname}}() { + public {{classname}}() { this(Configuration.getDefaultApiClient()); - } + } - public {{classname}}(ApiClient apiClient) { + public {{classname}}(ApiClient apiClient) { this.apiClient = apiClient; - } + } - public ApiClient getApiClient() { + public ApiClient getApiClient() { return apiClient; - } + } - public void setApiClient(ApiClient apiClient) { + public void setApiClient(ApiClient apiClient) { this.apiClient = apiClient; + } + + {{#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}} - {{#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}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}}; - // create path and map variables - String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}} - .replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}}; + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); - // query params - Map - queryParams = new HashMap - (); - Map - headerParams = new HashMap - (); - Map - formParams = new HashMap - (); + {{#queryParams}}if ({{paramName}} != null) + queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); + {{/queryParams}} - {{#queryParams}}if ({{paramName}} != null) - queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); - {{/queryParams}} + {{#headerParams}}if ({{paramName}} != null) + headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); + {{/headerParams}} - {{#headerParams}}if ({{paramName}} != null) - headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); - {{/headerParams}} + final String[] accepts = { + {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} + }; + final String accept = apiClient.selectHeaderAccept(accepts); - final String[] accepts = { - {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} - }; - final String accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} + }; + final String contentType = apiClient.selectHeaderContentType(contentTypes); - final String[] contentTypes = { - {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} - }; - final String contentType = apiClient.selectHeaderContentType(contentTypes); - - if(contentType.startsWith("multipart/form-data")) { - boolean hasFields = false; - FormDataMultiPart mp = new FormDataMultiPart(); - {{#formParams}}{{#notFile}} - if ({{paramName}} != null) { - hasFields = true; - mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE); - } - {{/notFile}}{{#isFile}} - if ({{paramName}} != null) { - hasFields = true; - mp.field("{{baseName}}", {{paramName}}.getName()); - mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE)); - } - {{/isFile}}{{/formParams}} - if(hasFields) + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + {{#formParams}}{{#notFile}} + if ({{paramName}} != null) { + hasFields = true; + mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE); + } + {{/notFile}}{{#isFile}} + if ({{paramName}} != null) { + hasFields = true; + mp.field("{{baseName}}", {{paramName}}.getName()); + mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE)); + } + {{/isFile}}{{/formParams}} + if(hasFields) postBody = mp; - } - else { - {{#formParams}}{{#notFile}}if ({{paramName}} != null) - formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}} - {{/formParams}} - } - - try { - String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; - String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames); - if(response != null){ - return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}}; - } - else { - return {{#returnType}}null{{/returnType}}; - } - } catch (ApiException ex) { - throw ex; - } - } - {{/operation}} } + else { + {{#formParams}}{{#notFile}}if ({{paramName}} != null) + formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}} + {{/formParams}} + } + + try { + String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; + String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames); + if(response != null){ + return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}}; + } + else { + return {{#returnType}}null{{/returnType}}; + } + } catch (ApiException ex) { + throw ex; + } + } + {{/operation}} +} {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/Java/apiException.mustache b/modules/swagger-codegen/src/main/resources/Java/apiException.mustache index 04d8767036c..9afe96c6ffb 100644 --- a/modules/swagger-codegen/src/main/resources/Java/apiException.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/apiException.mustache @@ -4,52 +4,44 @@ import java.util.Map; import java.util.List; public class ApiException extends Exception { -private int code = 0; -private String message = null; -private Map -> responseHeaders = null; - private String responseBody = null; + private int code = 0; + private String message = null; + private Map> responseHeaders = null; + private String responseBody = null; - public ApiException() {} + public ApiException() {} - public ApiException(int code, String message) { + public ApiException(int code, String message) { this.code = code; this.message = message; - } + } - public ApiException(int code, String message, Map - > responseHeaders, String responseBody) { - this.code = code; - this.message = message; - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } + public ApiException(int code, String message, Map> responseHeaders, String responseBody) { + this.code = code; + this.message = message; + this.responseHeaders = responseHeaders; + this.responseBody = responseBody; + } - public int getCode() { - return code; - } + public int getCode() { + return code; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - /** - * Get the HTTP response headers. - */ - public Map - > getResponseHeaders() { - return responseHeaders; - } + /** + * Get the HTTP response headers. + */ + public Map> getResponseHeaders() { + return responseHeaders; + } - /** - * Get the HTTP response body. - */ - public String getResponseBody() { - return responseBody; - } - } + /** + * Get the HTTP response body. + */ + public String getResponseBody() { + return responseBody; + } +} diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache index 3c6f5ef970a..65720b958cb 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache @@ -3,55 +3,53 @@ package {{invokerPackage}}.auth; import java.util.Map; public class ApiKeyAuth implements Authentication { -private final String location; -private final String paramName; + private final String location; + private final String paramName; -private String apiKey; -private String apiKeyPrefix; + private String apiKey; + private String apiKeyPrefix; -public ApiKeyAuth(String location, String paramName) { -this.location = location; -this.paramName = paramName; -} + public ApiKeyAuth(String location, String paramName) { + this.location = location; + this.paramName = paramName; + } -public String getLocation() { -return location; -} + public String getLocation() { + return location; + } -public String getParamName() { -return paramName; -} + public String getParamName() { + return paramName; + } -public String getApiKey() { -return apiKey; -} + public String getApiKey() { + return apiKey; + } -public void setApiKey(String apiKey) { -this.apiKey = apiKey; -} + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } -public String getApiKeyPrefix() { -return apiKeyPrefix; -} + public String getApiKeyPrefix() { + return apiKeyPrefix; + } -public void setApiKeyPrefix(String apiKeyPrefix) { -this.apiKeyPrefix = apiKeyPrefix; -} + public void setApiKeyPrefix(String apiKeyPrefix) { + this.apiKeyPrefix = apiKeyPrefix; + } -@Override -public void applyToParams(Map - queryParams, Map - headerParams) { -String value; -if (apiKeyPrefix != null) { -value = apiKeyPrefix + " " + apiKey; -} else { -value = apiKey; -} -if (location == "query") { -queryParams.put(paramName, value); -} else if (location == "header") { -headerParams.put(paramName, value); -} -} + @Override + public void applyToParams(Map queryParams, Map headerParams) { + String value; + if (apiKeyPrefix != null) { + value = apiKeyPrefix + " " + apiKey; + } else { + value = apiKey; + } + if (location == "query") { + queryParams.put(paramName, value); + } else if (location == "header") { + headerParams.put(paramName, value); + } + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/Authentication.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/Authentication.mustache index 50ec5be52dc..1b2e2bc2fbe 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/Authentication.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/Authentication.mustache @@ -3,8 +3,6 @@ package {{invokerPackage}}.auth; import java.util.Map; public interface Authentication { -/** Apply authentication settings to header and query params. */ -void applyToParams(Map - queryParams, Map - headerParams); + /** Apply authentication settings to header and query params. */ + void applyToParams(Map queryParams, Map headerParams); } diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache index de8d8864c6a..22a64b1a24e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache @@ -6,34 +6,32 @@ import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; public class HttpBasicAuth implements Authentication { -private String username; -private String password; + private String username; + private String password; -public String getUsername() { -return username; -} + public String getUsername() { + return username; + } -public void setUsername(String username) { -this.username = username; -} + public void setUsername(String username) { + this.username = username; + } -public String getPassword() { -return password; -} + public String getPassword() { + return password; + } -public void setPassword(String password) { -this.password = password; -} + public void setPassword(String password) { + this.password = password; + } -@Override -public void applyToParams(Map - queryParams, Map - headerParams) { -String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); -try { -headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); -} catch (UnsupportedEncodingException e) { -throw new RuntimeException(e); -} -} + @Override + public void applyToParams(Map queryParams, Map headerParams) { + String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + try { + headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/OAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/OAuth.mustache index 98e4be6182b..ef84b8cc05e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/OAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/OAuth.mustache @@ -3,10 +3,8 @@ package {{invokerPackage}}.auth; import java.util.Map; public class OAuth implements Authentication { -@Override -public void applyToParams(Map - queryParams, Map - headerParams) { -// TODO: support oauth -} + @Override + public void applyToParams(Map queryParams, Map headerParams) { + // TODO: support oauth + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/model.mustache b/modules/swagger-codegen/src/main/resources/Java/model.mustache index b38008ebc35..0e12f514c48 100644 --- a/modules/swagger-codegen/src/main/resources/Java/model.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/model.mustache @@ -7,45 +7,45 @@ import io.swagger.annotations.*; import com.fasterxml.jackson.annotation.JsonProperty; {{#models}} - {{#model}}{{#description}} - /** - * {{description}} - **/{{/description}} - @ApiModel(description = "{{{description}}}") - public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { - {{#vars}}{{#isEnum}} - public enum {{datatypeWithEnum}} { - {{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}} - }; - private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}} - private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}} +{{#model}}{{#description}} +/** + * {{description}} + **/{{/description}} +@ApiModel(description = "{{{description}}}") +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { + {{#vars}}{{#isEnum}} + public enum {{datatypeWithEnum}} { + {{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}} + }; + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}} + private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}} - {{#vars}} - /**{{#description}} - * {{{description}}}{{/description}}{{#minimum}} - * minimum: {{minimum}}{{/minimum}}{{#maximum}} - * maximum: {{maximum}}{{/maximum}} - **/ - @ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") - @JsonProperty("{{baseName}}") - public {{{datatypeWithEnum}}} {{getter}}() { - return {{name}}; - } - public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { - this.{{name}} = {{name}}; - } + {{#vars}} + /**{{#description}} + * {{{description}}}{{/description}}{{#minimum}} + * minimum: {{minimum}}{{/minimum}}{{#maximum}} + * maximum: {{maximum}}{{/maximum}} + **/ + @ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + @JsonProperty("{{baseName}}") + public {{{datatypeWithEnum}}} {{getter}}() { + return {{name}}; + } + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } - {{/vars}} + {{/vars}} - @Override - public String toString() { + @Override + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class {{classname}} {\n"); {{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}} {{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n"); {{/vars}}sb.append("}\n"); return sb.toString(); - } - } - {{/model}} + } +} +{{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index d18fa9284c7..592edeec051 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -1,170 +1,167 @@ - 4.0.0 - {{groupId}} - {{artifactId}} - jar - {{artifactId}} - {{artifactVersion}} - - scm:git:git@github.com:swagger-api/swagger-mustache.git - scm:git:git@github.com:swagger-api/swagger-codegen.git - https://github.com/swagger-api/swagger-codegen - - - 2.2.0 - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + scm:git:git@github.com:swagger-api/swagger-mustache.git + scm:git:git@github.com:swagger-api/swagger-codegen.git + https://github.com/swagger-api/swagger-codegen + + + 2.2.0 + - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12 - - - - loggerPath - conf/log4j.properties - - - -Xms512m -Xmx1500m - methods - pertest - - - - maven-dependency-plugin - - - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + + + loggerPath + conf/log4j.properties + + + -Xms512m -Xmx1500m + methods + pertest + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + - - - org.apache.maven.plugins - maven-jar-plugin - 2.2 - - - - jar - test-jar - - - - - - + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + jar + test-jar + + + + + + - - org.codehaus.mojo - build-helper-maven-plugin - - - add_sources - generate-sources - - add-source - - - - - src/main/java - - - - - add_test_sources - generate-test-sources - - add-test-source - - - - - src/test/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - - 1.6 - 1.6 - - - - - - - io.swagger - swagger-annotations - ${swagger-annotations-version} - - - com.sun.jersey - jersey-client - ${jersey-version} - - - com.sun.jersey.contribs - jersey-multipart - ${jersey-version} - - - com.fasterxml.jackson.core - jackson-core - ${jackson-version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson-version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson-version} - - - com.fasterxml.jackson.datatype - jackson-datatype-joda - 2.1.5 - - - joda-time - joda-time - ${jodatime-version} - + + org.codehaus.mojo + build-helper-maven-plugin + + + add_sources + generate-sources + + add-source + + + + src/main/java + + + + + add_test_sources + generate-test-sources + + add-test-source + + + + src/test/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + + + io.swagger + swagger-annotations + ${swagger-annotations-version} + + + com.sun.jersey + jersey-client + ${jersey-version} + + + com.sun.jersey.contribs + jersey-multipart + ${jersey-version} + + + com.fasterxml.jackson.core + jackson-core + ${jackson-version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson-version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-version} + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + 2.1.5 + + + joda-time + joda-time + ${jodatime-version} + - - - junit - junit - ${junit-version} - test - - - - 1.5.0 - 1.18 - 2.4.2 - 2.3 - 1.0.0 - 4.8.1 - + + + junit + junit + ${junit-version} + test + + + + 1.5.0 + 1.18 + 2.4.2 + 2.3 + 1.0.0 + 4.8.1 +