From e2dbe61adf4b75e861ed4737055a23fa4d2ae25e Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sun, 23 Sep 2012 18:43:14 -0700 Subject: [PATCH] updated to use swagger 1.1.0 --- src/main/resources/Java/apiInvoker.mustache | 55 +++++++++++---------- src/main/resources/Java/pom.mustache | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/resources/Java/apiInvoker.mustache b/src/main/resources/Java/apiInvoker.mustache index f4349548fa7..05dd2d0cd24 100644 --- a/src/main/resources/Java/apiInvoker.mustache +++ b/src/main/resources/Java/apiInvoker.mustache @@ -1,8 +1,11 @@ -package com.wordnik.client; +package {{package}}; import com.wordnik.swagger.core.util.JsonUtil; -import org.codehaus.jackson.type.JavaType; +import com.fasterxml.jackson.core.JsonGenerator.Feature; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; @@ -28,7 +31,7 @@ public class ApiInvoker { } public void addDefaultHeader(String key, String value) { - defaultHeaderMap.put(key, value); + defaultHeaderMap.put(key, value); } public String escapeString(String str) { @@ -38,7 +41,7 @@ public class ApiInvoker { public static Object deserialize(String json, String containerType, Class cls) throws ApiException { try{ if("List".equals(containerType)) { - JavaType typeInfo = org.codehaus.jackson.map.type.TypeFactory.collectionType(List.class, cls); + JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls); List response = (List) JsonUtil.getJsonMapper().readValue(json, typeInfo); return response; } @@ -74,58 +77,58 @@ public class ApiInvoker { 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 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 = client.resource(host + path + querystring).type("application/json"); for(String key : headerParams.keySet()) { - builder.header(key, headerParams.get(key)); + builder.header(key, headerParams.get(key)); } for(String key : defaultHeaderMap.keySet()) { - if(!headerParams.containsKey(key)) { - builder.header(key, defaultHeaderMap.get(key)); - } + if(!headerParams.containsKey(key)) { + builder.header(key, defaultHeaderMap.get(key)); + } } ClientResponse response = null; if("GET".equals(method)) { - response = (ClientResponse) builder.get(ClientResponse.class); + response = (ClientResponse) builder.get(ClientResponse.class); } else if ("POST".equals(method)) { response = builder.post(ClientResponse.class, serialize(body)); } else if ("PUT".equals(method)) { - response = builder.put(ClientResponse.class, serialize(body)); + response = builder.put(ClientResponse.class, serialize(body)); } else if ("DELETE".equals(method)) { response = builder.delete(ClientResponse.class, serialize(body)); } else { - throw new ApiException(500, "unknown method type " + method); + throw new ApiException(500, "unknown method type " + method); } if(response.getClientResponseStatus() == ClientResponse.Status.OK) { - return (String) response.getEntity(String.class); + return (String) response.getEntity(String.class); } else { - throw new ApiException( - response.getClientResponseStatus().getStatusCode(), - response.getEntity(String.class)); + throw new ApiException( + response.getClientResponseStatus().getStatusCode(), + response.getEntity(String.class)); } } private Client getClient(String host) { - if(!hostMap.containsKey(host)) { - Client client = Client.create(); - client.addFilter(new LoggingFilter()); + if(!hostMap.containsKey(host)) { + Client client = Client.create(); + client.addFilter(new LoggingFilter()); hostMap.put(host, client); - } - return hostMap.get(host); + } + return hostMap.get(host); } } \ No newline at end of file diff --git a/src/main/resources/Java/pom.mustache b/src/main/resources/Java/pom.mustache index 2431a36a483..907976e6a42 100644 --- a/src/main/resources/Java/pom.mustache +++ b/src/main/resources/Java/pom.mustache @@ -213,7 +213,7 @@ 1.7 - 1.02-SNAPSHOT + 1.1.0 2.9.1-1 4.8.1 1.0.0