forked from loafle/openapi-generator-original
Updated code gen to fix some logic issues
This commit is contained in:
parent
976493b69b
commit
cc72163683
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<project name="wordnik-java-driver" xmlns:ivy="antlib:org.apache.ivy.ant" default="fastdist" basedir=".">
|
||||
<property environment="env" />
|
||||
<property name="version.identifier" value="4.04" />
|
||||
|
||||
<!-- property name="application.description" value="Wordnik Java Driver"/>
|
||||
<property name="application.name" value="java-driver"/ -->
|
||||
<condition property="build.common.dir" value="${env.BUILD_COMMON}">
|
||||
<isset property="env.BUILD_COMMON" />
|
||||
</condition>
|
||||
<echo message="using build common dir: ${build.common.dir}"/>
|
||||
|
||||
<target name="runtests" description="runs the test cases" depends="compile, test.compile">
|
||||
<java classname="com.wordnik.swagger.test.APITestRunner">
|
||||
<arg value="JAVA" />
|
||||
<classpath>
|
||||
<pathelement location="build/main/java" />
|
||||
<pathelement location="build/test/java" />
|
||||
<fileset dir="lib">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Creating directories used in app structure if required-->
|
||||
<mkdir dir="build/main"/>
|
||||
<mkdir dir="build/test"/>
|
||||
<mkdir dir="lib/ext"/>
|
||||
<mkdir dir="bin"/>
|
||||
<mkdir dir="src/main/scala"/>
|
||||
<mkdir dir="src/main/java"/>
|
||||
<mkdir dir="src/test/java"/>
|
||||
<mkdir dir="src/test/scala"/>
|
||||
|
||||
<target name="merge.custom" description="Copying from the lang folder to merge with generated">
|
||||
<copy todir="../java/src/main/java/" overwrite="true">
|
||||
<fileset dir="../java/src/lang"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<import file="${build.common.dir}/ant/ant-common.xml" />
|
||||
<import file="${build.common.dir}/ant/ant-test.xml" />
|
||||
<import file="${build.common.dir}/ant/ant-server.xml" />
|
||||
</project>
|
@ -1,41 +0,0 @@
|
||||
<ivy-module version="2.0">
|
||||
<info organisation="wordnik" module="wordnik-java-driver"/>
|
||||
<configurations>
|
||||
<conf name="build" description="build wordnik-java"/>
|
||||
<conf name="test" visibility="public"/>
|
||||
<conf name="source" visibility="public"/>
|
||||
<conf name="pom" visibility="public"/>
|
||||
</configurations>
|
||||
|
||||
<publications>
|
||||
<artifact name="wordnik-java-driver" type="jar" conf="build" ext="jar"/>
|
||||
<artifact name="wordnik-java-driver" type="pom" conf="pom" ext="pom"/>
|
||||
<artifact name="wordnik-java-driver-source" type="source" conf="source" ext="zip"/>
|
||||
<artifact name="wordnik-java-driver-test" type="jar" conf="test" ext="jar"/>
|
||||
</publications>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency org="wordnik" name="wordnik-libs-gen" rev="1.0.+"/>
|
||||
|
||||
<!-- jersey dependencies -->
|
||||
<dependency org="junit" name="junit" rev="4.4" conf="build->default"/>
|
||||
<dependency org="com.sun.jersey" name="jersey-json" rev="1.4" conf="build->default"/>
|
||||
<dependency org="com.sun.jersey" name="jersey-client" rev="1.4" conf="build->default"/>
|
||||
<dependency org="com.sun.jersey" name="jersey-server" rev="1.4" conf="build->default"/>
|
||||
<dependency org="com.sun.jersey" name="jersey-core" rev="1.4" conf="build->default"/>
|
||||
<dependency org="asm" name="asm-parent" rev="3.1" conf="build->default"/>
|
||||
<dependency org="commons-beanutils" name="commons-beanutils" rev="1.8.0" conf="build->default"/>
|
||||
<dependency org="org.antlr" name="stringtemplate" rev="3.2" conf="build->default"/>
|
||||
<!-- jackson jars -->
|
||||
<dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.7.1" conf="build->default"/>
|
||||
<dependency org="org.codehaus.jackson" name="jackson-xc" rev="1.7.1" conf="build->default"/>
|
||||
<dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.7.1" conf="build->default"/>
|
||||
|
||||
|
||||
<dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.2" conf="test->default">
|
||||
<exclude org="asm" name="asm-tree"/>
|
||||
<exclude org="asm" name="asm"/>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</ivy-module>
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<String,
|
||||
public static String invokeAPI(String resourceURL, String method, Map<String,
|
||||
String> 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<String, String> headerMap = new HashMap<String, String>();
|
||||
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();
|
||||
}
|
||||
}
|
@ -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<String, String> httpHeaders);
|
||||
}
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
*/
|
||||
|
@ -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
|
||||
*
|
||||
*/
|
||||
|
@ -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<ArrayList<$method.returnClassName$>> typeRef = new TypeReference<ArrayList<$method.returnClassName$>>() {
|
||||
};
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
*/
|
||||
|
@ -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<Resource> resources, StringTemplateGroup templateGroup) {
|
||||
List<String> 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<Resource> resources, StringTemplateGroup templateGroup) {
|
||||
|
||||
//delete previously generated files
|
||||
FileUtil.cleanFiles(languageConfig.getResourceClassLocation());
|
||||
|
||||
for(Resource resource : resources) {
|
||||
List<ResourceMethod> methods = new ArrayList<ResourceMethod>();
|
||||
List<String> imports = new ArrayList<String>();
|
||||
@ -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<String> imports = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user