diff --git a/conf/java/structure/build.xml b/conf/java/structure/build.xml
deleted file mode 100644
index af23a0a1d32..00000000000
--- a/conf/java/structure/build.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/conf/java/structure/ivy.xml b/conf/java/structure/ivy.xml
deleted file mode 100644
index ec44869bb26..00000000000
--- a/conf/java/structure/ivy.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/AllowableValues.java b/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/AllowableValues.java
index bc162b068ec..7d81cce8f52 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/AllowableValues.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/AllowableValues.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.annotations;
import java.lang.annotation.ElementType;
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/MethodArgumentNames.java b/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/MethodArgumentNames.java
index 01aaac0093f..a178848f74d 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/MethodArgumentNames.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/MethodArgumentNames.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.annotations;
import java.lang.annotation.ElementType;
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/Required.java b/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/Required.java
index e3fa6402548..3eda04d2f7d 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/Required.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/annotations/Required.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.annotations;
import java.lang.annotation.ElementType;
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/common/WordnikAPI.java b/conf/java/structure/src/main/java/com/wordnik/swagger/common/APIInvoker.java
similarity index 69%
rename from conf/java/structure/src/main/java/com/wordnik/swagger/common/WordnikAPI.java
rename to conf/java/structure/src/main/java/com/wordnik/swagger/common/APIInvoker.java
index 011f1423dbf..a0b76b52f7d 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/common/WordnikAPI.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/common/APIInvoker.java
@@ -1,7 +1,26 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.common;
import java.io.IOException;
+import java.lang.String;
import java.util.Map;
+import java.util.List;
+import java.util.HashMap;
import java.util.logging.Logger;
import javax.ws.rs.core.MultivaluedMap;
@@ -21,15 +40,18 @@ import com.sun.jersey.api.client.filter.LoggingFilter;
/**
- * Provides way to initialize the communication with Wordnik API server.
- * This is also a Base class for all API classes
+ * Provides method to initialize the api server settings and also handles the logic related to invoking the API server
+ * along with serealizing and deserializing input and output responses.
+ *
+ * This is also a Base class for all API classes
+ *
* @author ramesh
*
*/
-public class WordnikAPI {
+public class APIInvoker {
private static String apiServer = "http://api.wordnik.com/v4";
- private static String apiKey = "";
+ private static SecurityHandler securityHandler = null;
private static boolean loggingEnabled;
private static Logger logger = null;
@@ -37,7 +59,7 @@ public class WordnikAPI {
protected static String GET = "GET";
protected static String PUT = "PUT";
protected static String DELETE = "DELETE";
- protected static ObjectMapper mapper = new ObjectMapper();
+ public static ObjectMapper mapper = new ObjectMapper();
static{
mapper.getDeserializationConfig().set(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.getSerializationConfig().set(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
@@ -47,7 +69,7 @@ public class WordnikAPI {
/**
* Initializes the API communication with required inputs.
- * @param apiKey provide the key provided as part of registration
+ * @param securityHandler security handler responsible for populating necessary security invocation while making API server calls
* @param apiServer Sets the URL for the API server. It is defaulted to the server
* used while building the driver. This value should be provided while testing the APIs against
* test servers or if there is any changes in production server URLs.
@@ -55,8 +77,8 @@ public class WordnikAPI {
* for more details. {@link com.sun.jersey.api.client.filter.LoggingFilter}. Default output is sent to system.out.
* Create a logger ({@link java.util.logging.Logger} class and set using setLogger method.
*/
- public static void initialize(String apiKey, String apiServer, boolean enableLogging) {
- setApiKey(apiKey);
+ public static void initialize(SecurityHandler securityHandler, String apiServer, boolean enableLogging) {
+ setSecurityHandler(securityHandler);
if(apiServer != null && apiServer.length() > 0) {
if(apiServer.substring(apiServer.length()-1).equals("/")){
apiServer = apiServer.substring(0, apiServer.length()-1);
@@ -79,12 +101,12 @@ public class WordnikAPI {
* This value is set using initialize method.
* @return
*/
- public static String getApiKey() {
- return apiKey;
+ public static SecurityHandler setSecurityHandler() {
+ return securityHandler;
}
- private static void setApiKey(String apiKey) {
- WordnikAPI.apiKey = apiKey;
+ private static void setSecurityHandler(SecurityHandler aSecurityHandler) {
+ securityHandler = aSecurityHandler;
}
/**
@@ -95,38 +117,36 @@ public class WordnikAPI {
return apiServer;
}
- private static void setApiServer(String server) {
- WordnikAPI.apiServer = server;
+ public static void setApiServer(String server) {
+ apiServer = server;
}
/**
* Invokes the API and returns the response as json string.
- * This is an internal method called by individual APIs for communication. It sets the required HTTP headers
- * based on API key and auth token.
- * @param authToken - token that is received as part of authentication call. This is only needed for the calls that are secure.
+ *
+ * This is an internal method called by individual APIs for communication. It sets the required security information
+ * based ons ecuroty handler
+ *
* @param resourceURL - URL for the rest resource
* @param method - Method we should use for communicating to the back end.
* @param postObject - if the method is POST, provide the object that should be sent as part of post request.
* @return JSON response of the API call.
* @throws com.wordnik.swagger.exception.APIException if the call to API server fails.
*/
- protected static String invokeAPI(String authToken, String resourceURL, String method, Map queryParams, Object postObject) throws APIException {
Client apiClient = Client.create();
- //check for app key and server values
- if(getApiKey() == null || getApiKey().length() == 0) {
- String[] args = {getApiKey()};
- throw new APIException(APIExceptionCodes.API_KEY_NOT_VALID, args);
- }
+ //check for app server values
if(getApiServer() == null || getApiServer().length() == 0) {
String[] args = {getApiServer()};
throw new APIException(APIExceptionCodes.API_SERVER_NOT_VALID, args);
}
+
//initialize the logger if needed
if(loggingEnabled) {
if(logger == null) {
@@ -149,15 +169,19 @@ public class WordnikAPI {
i++;
}
}
+ Map headerMap = new HashMap();
+ if(securityHandler != null){
+ securityHandler.populateSecurityInfo(resourceURL, headerMap);
+ }
WebResource aResource = apiClient.resource(resourceURL);
- // aResource.queryParams(queryParams);
-
+
+
//set the required HTTP headers
Builder builder = aResource.type("application/json");
- builder.header("api_key", getApiKey());
- if(authToken != null){
- builder.header("auth_token", authToken);
+ for(String key : headerMap.keySet()){
+ builder.header(key, headerMap.get(key));
}
+
ClientResponse clientResponse = null;
if(method.equals(GET)) {
clientResponse = builder.get(ClientResponse.class);
@@ -187,7 +211,6 @@ public class WordnikAPI {
*/
public static Object deserialize(String response, Class inputClassName) throws APIException {
try {
- System.out.println("Input :::::" + response);
Object responseObject = mapper.readValue(response, inputClassName);
return responseObject;
} catch (IOException ioe) {
@@ -212,5 +235,34 @@ public class WordnikAPI {
} catch (IOException ioe) {
throw new APIException(APIExceptionCodes.ERROR_CONVERTING_JAVA_TO_JSON, "Error in coverting input java to json : " + ioe.getMessage(), ioe);
}
- }
+ }
+
+
+ /**
+ * Overloaded method for returning the path value
+ * For a string value an empty value is returned if the value is null
+ * @param value
+ * @return
+ */
+ public static String toPathValue(String value) {
+ return value == null ? "" : value;
+ }
+
+ /**
+ * Overloaded method for returning a path value
+ * For a list of objects a comma separated string is returned
+ * @param objects
+ * @return
+ */
+ public static String toPathValue(List objects) {
+ StringBuilder out = new StringBuilder();
+ for(Object o: objects){
+ out.append(o.toString());
+ out.append(",");
+ }
+ if(out.indexOf(",") != -1) {
+ return out.substring(0, out.lastIndexOf(",") );
+ }
+ return out.toString();
+ }
}
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/common/SecurityHandler.java b/conf/java/structure/src/main/java/com/wordnik/swagger/common/SecurityHandler.java
new file mode 100644
index 00000000000..a2224f85825
--- /dev/null
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/common/SecurityHandler.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.wordnik.swagger.common;
+
+import java.util.Map;
+
+/**
+ * Provide methods that are responsible for handling security aspect while communicating with the backend server.
+ *
+ * Example: For some cases API key may need to be passed in the headers for all server communication and some times
+ * user authentication token may need to be passed along with api key.
+ *
+ * Implementers of this class are responsible for handling storing information related to secutiry and sending it
+ * along with all API calls
+ *
+ * User: ramesh
+ * Date: 4/12/11
+ * Time: 5:46 PM
+ */
+public interface SecurityHandler {
+
+ /**
+ * Populate the security infomration in http headers map and/or reqsource URL.
+ *
+ * Value spopulated in the http headers map will be set as http headers while making the server communication.
+ *
+ * Depending on the usecase requried information can be added to either of them or both.
+ *
+ * @param resourceURL
+ * @param headers
+ */
+ public void populateSecurityInfo(String resourceURL, Map httpHeaders);
+}
\ No newline at end of file
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/common/StringValue.java b/conf/java/structure/src/main/java/com/wordnik/swagger/common/StringValue.java
index 4c7eaef40f0..6fcbdfcd52d 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/common/StringValue.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/common/StringValue.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.common;
/**
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIException.java b/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIException.java
index 61e98e24326..1511175a97c 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIException.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIException.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.exception;
import com.sun.jersey.api.client.ClientResponse;
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIExceptionCodes.java b/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIExceptionCodes.java
index 688f7342f98..56ec3c65837 100644
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIExceptionCodes.java
+++ b/conf/java/structure/src/main/java/com/wordnik/swagger/exception/APIExceptionCodes.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.wordnik.swagger.exception;
/**
diff --git a/conf/java/structure/src/main/java/com/wordnik/swagger/exception/CodeGenerationException.java b/conf/java/structure/src/main/java/com/wordnik/swagger/exception/CodeGenerationException.java
deleted file mode 100644
index 308f4a27338..00000000000
--- a/conf/java/structure/src/main/java/com/wordnik/swagger/exception/CodeGenerationException.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.wordnik.swagger.exception;
-
-/**
- * Exception raised while generating code for java driver.
- * User: ramesh
- * Date: 3/31/11
- * Time: 9:29 AM
- */
-public class CodeGenerationException extends RuntimeException {
-
- private String message;
-
- public CodeGenerationException(String message){
- this.message = message;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-}
-
diff --git a/conf/java/templates/EnumObject.st b/conf/java/templates/EnumObject.st
index 9cbc2c661c5..f93d4d5c717 100644
--- a/conf/java/templates/EnumObject.st
+++ b/conf/java/templates/EnumObject.st
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package $packageName$;
$imports:{ import |
@@ -6,7 +22,7 @@ import $import$;
/**
* $enum.description$
- * NOTE: This class is auto generated by the drive code generator program so please do not edit the class manually.
+ * NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
* @author deepak
*
*/
diff --git a/conf/java/templates/ModelObject.st b/conf/java/templates/ModelObject.st
index 75ebd5a1999..3b44e4eddbf 100644
--- a/conf/java/templates/ModelObject.st
+++ b/conf/java/templates/ModelObject.st
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package $packageName$;
import $annotationPackageName$.AllowableValues;
@@ -9,7 +25,9 @@ import $import$;
/**
* $model.description$
- * NOTE: This class is auto generated by the drive code generator program so please do not edit the class manually.
+ *
+ * NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
+ *
* @author ramesh
*
*/
diff --git a/conf/java/templates/ResourceObject.st b/conf/java/templates/ResourceObject.st
index 3887c24b919..06efc446db2 100644
--- a/conf/java/templates/ResourceObject.st
+++ b/conf/java/templates/ResourceObject.st
@@ -1,4 +1,20 @@
-package $packageName$;
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package $packageName$;
import $annotationPackageName$.MethodArgumentNames;
@@ -9,6 +25,9 @@ import $modelPackageName$.*;
import org.codehaus.jackson.map.DeserializationConfig.Feature;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
+import com.wordnik.swagger.annotations.*;
+import com.wordnik.swagger.common.*;
+import com.wordnik.swagger.exception.*;
import java.util.*;
import java.io.IOException;
@@ -18,7 +37,8 @@ import $import$;
}$
/**
- * NOTE: This class is auto generated by the drive code generator program so please do not edit the class manually.
+ *
+ * NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
* @author ramesh
*
*/
@@ -44,12 +64,6 @@ $endif$
public static $method.returnValue$ $method.name$($method.argumentDefinitions; separator=", "$) throws APIException {
-$if(method.authToken)$
- if(authToken == null || authToken.length() == 0) {
- throw new APIException(APIExceptionCodes.AUTH_TOKEN_NOT_VALID);
- }
-$endif$
-
//parse inputs
String resourcePath = "$method.resourcePath$";
resourcePath = resourcePath.replace("{format}","json");
@@ -58,7 +72,7 @@ $endif$
$if(!method.inputModel)$
$method.queryParameters:{ argument |
if( $argument.name$ != null) {
- queryParams.put("$argument.name$", toPathValue($argument.name$));
+ queryParams.put("$argument.name$", APIInvoker.toPathValue($argument.name$));
}
}$
$method.pathParameters:{ argument |
@@ -81,21 +95,11 @@ $method.pathParameters:{ argument |
$endif$
//make the API Call
$if(method.postObject)$
-$if(method.authToken)$
- String response = invokeAPI(authToken, resourcePath, method, queryParams, postObject);
-$endif$
-$if(!method.authToken)$
- String response = invokeAPI(null, resourcePath, method, queryParams, postObject);
-$endif$
+ String response = APIInvoker.invokeAPI(resourcePath, method, queryParams, postObject);
$endif$
$if(!method.postObject)$
-$if(method.authToken)$
- String response = invokeAPI(authToken, resourcePath, method, queryParams, null);
-$endif$
-$if(!method.authToken)$
- String response = invokeAPI(null, resourcePath, method, queryParams, null);
-$endif$
+ String response = APIInvoker.invokeAPI(resourcePath, method, queryParams, null);
$endif$
//create output objects if the response has more than one object
@@ -104,14 +108,14 @@ $if(!method.responseVoid)$
return null;
}
$if(!method.returnValueList)$
- $method.returnValue$ responseObject = ($method.returnValue$)deserialize(response, $method.returnClassName$.class);
+ $method.returnValue$ responseObject = ($method.returnValue$) APIInvoker.deserialize(response, $method.returnClassName$.class);
return responseObject;
$endif$
$if(method.returnValueList)$
TypeReference> typeRef = new TypeReference>() {
};
try {
- List<$method.returnClassName$> responseObject = (List<$method.returnClassName$>) mapper.readValue(response, typeRef);
+ List<$method.returnClassName$> responseObject = (List<$method.returnClassName$>) APIInvoker.mapper.readValue(response, typeRef);
return responseObject;
} catch (IOException ioe) {
String[] args = new String[]{response, typeRef.toString()};
@@ -123,31 +127,4 @@ $endif$
}$
- /**
- * Overloaded method for returning the path value
- * For a string value an empty value is returned if the value is null
- * @param value
- * @return
- */
- private static String toPathValue(String value) {
- return value == null ? "" : value;
- }
-
- /**
- * Overloaded method for returning a path value
- * For a list of objects a comma separated string is returned
- * @param objects
- * @return
- */
- private static String toPathValue(List objects) {
- StringBuilder out = new StringBuilder();
- for(Object o: objects){
- out.append(o.toString());
- out.append(",");
- }
- if(out.indexOf(",") != -1) {
- return out.substring(0, out.lastIndexOf(",") );
- }
- return out.toString();
- }
}
diff --git a/conf/java/templates/VersionChecker.st b/conf/java/templates/VersionChecker.st
index 1044bd190cb..7264a9d68dc 100644
--- a/conf/java/templates/VersionChecker.st
+++ b/conf/java/templates/VersionChecker.st
@@ -1,7 +1,25 @@
+/**
+ * Copyright 2011 Wordnik, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package $packageName$;
/**
+ *
* Maintains the compatible server version against which the drive is written
+ * NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
* @author ramesh
*
*/
diff --git a/src/main/java/com/wordnik/swagger/codegen/LibraryCodeGenerator.java b/src/main/java/com/wordnik/swagger/codegen/LibraryCodeGenerator.java
index cf1c654ed76..91d67402aab 100644
--- a/src/main/java/com/wordnik/swagger/codegen/LibraryCodeGenerator.java
+++ b/src/main/java/com/wordnik/swagger/codegen/LibraryCodeGenerator.java
@@ -4,6 +4,7 @@ import com.wordnik.swagger.codegen.api.SwaggerResourceDocReader;
import com.wordnik.swagger.codegen.config.*;
import com.wordnik.swagger.codegen.config.ApiConfiguration;
import com.wordnik.swagger.codegen.resource.*;
+import com.wordnik.swagger.codegen.util.FileUtil;
import com.wordnik.swagger.exception.CodeGenerationException;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
@@ -73,6 +74,9 @@ public class LibraryCodeGenerator {
private void generateModelClasses(List resources, StringTemplateGroup templateGroup) {
List generatedClassNames = new ArrayList();
+ //remove old generated files
+ FileUtil.cleanFiles(languageConfig.getModelClassLocation());
+
for(Resource resource: resources) {
for(Model model : resource.getModels()){
if(!generatedClassNames.contains(model.getName()) && !this.getCodeGenRulesProvider().isModelIgnored(model.getName())){
@@ -212,6 +216,9 @@ public class LibraryCodeGenerator {
*/
private void generateAPIClasses(List resources, StringTemplateGroup templateGroup) {
+ //delete previously generated files
+ FileUtil.cleanFiles(languageConfig.getResourceClassLocation());
+
for(Resource resource : resources) {
List methods = new ArrayList();
List imports = new ArrayList();
@@ -256,12 +263,6 @@ public class LibraryCodeGenerator {
modelFields.add(aParam);
}
- //add missing class from models
- ModelField aParam = new ModelField();
- aParam.setName("StringValueList");
- aParam.setParamType(this.getDataTypeMappingProvider().getListReturnTypeSignature("StringValue"));
- modelFields.add(aParam);
-
List imports = new ArrayList();
imports.addAll(this.config.getDefaultModelImports());
imports.addAll(this.getDataTypeMappingProvider().getListImportPackages());
@@ -293,7 +294,7 @@ public class LibraryCodeGenerator {
throw new CodeGenerationException("Error generating " + classType + " : " + ioe.getMessage());
}
}
-
+
public ApiConfiguration getConfig() {
return config;
}
diff --git a/src/main/java/com/wordnik/swagger/codegen/config/java/JavaLibCodeGen.java b/src/main/java/com/wordnik/swagger/codegen/config/java/JavaLibCodeGen.java
index 5a32e6e4521..8a8db1a82e6 100644
--- a/src/main/java/com/wordnik/swagger/codegen/config/java/JavaLibCodeGen.java
+++ b/src/main/java/com/wordnik/swagger/codegen/config/java/JavaLibCodeGen.java
@@ -87,7 +87,9 @@ public class JavaLibCodeGen extends LibraryCodeGenerator {
//create ouput directories
FileUtil.createOutputDirectories(javaConfiguration.getModelClassLocation(), javaConfiguration.getClassFileExtension());
FileUtil.createOutputDirectories(javaConfiguration.getResourceClassLocation(), javaConfiguration.getClassFileExtension());
-
+ FileUtil.cleanFiles(javaConfiguration.getApiServerRootLocation()+ "/src/main/java/com/wordnik/swagger/common");
+ FileUtil.cleanFiles(javaConfiguration.getApiServerRootLocation()+ "/src/main/java/com/wordnik/swagger/exception");
+ FileUtil.cleanFiles(javaConfiguration.getApiServerRootLocation()+ "/src/main/java/com/wordnik/swagger/annotations");
FileUtil.copyDirectory(new File(javaConfiguration.getStructureLocation()), new File(javaConfiguration.getApiServerRootLocation()));
return javaConfiguration;
}
diff --git a/src/main/java/com/wordnik/swagger/codegen/util/FileUtil.java b/src/main/java/com/wordnik/swagger/codegen/util/FileUtil.java
index 4863900aa79..cfe1bd56d45 100644
--- a/src/main/java/com/wordnik/swagger/codegen/util/FileUtil.java
+++ b/src/main/java/com/wordnik/swagger/codegen/util/FileUtil.java
@@ -27,6 +27,19 @@ public class FileUtil {
return oFile.delete();
}
+
+ /**
+ * Deleet all the files from the specified location
+ * @param directoryLocation
+ */
+ public static void cleanFiles(String directoryLocation) {
+ File fDir = new File(directoryLocation);
+ File[] files = fDir.listFiles();
+ for(File aFile : files) {
+ aFile.delete();
+ }
+ }
+
// Clears the folder of the files with extension
public static void clearFolder(String strFolder, final String strExt) {
File fLogDir = new File(strFolder);
@@ -41,6 +54,7 @@ public class FileUtil {
}
}
+
public static void copyDirectory(File srcPath, File dstPath) {
if (srcPath.isDirectory()) {
if (!dstPath.exists()) {