/** * 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; //import $exceptionPackageName$.APIExceptionCodes; //import $exceptionPackageName$.APIException; 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.runtime.annotations.*; import com.wordnik.swagger.runtime.common.*; import com.wordnik.swagger.runtime.exception.*; import java.util.*; import java.io.IOException; $imports:{ import | import $import$; }$ /** * * NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. * @author ramesh * */ public class $resource$ extends $extends$ { $methods:{ method | /** * $method.title$ * $if(method.description)$ * $method.description$ * $endif$ * $method.arguments:{ argument |@param $argument.name$ $argument.description$ * $if(argument.allowedValues)$ * Allowed values are - $argument.allowedValues$ $endif$ }$ $if(!method.responseVoid)$ * @return $method.returnValue$ {@link $method.returnClassName$} $endif$ * @throws APIException $method.exceptionDescription$ */ $if(method.hasArguments)$ @MethodArgumentNames(value="$method.argumentNames; separator=", "$") $endif$ public static $method.returnValue$ $method.name$($method.argumentDefinitions; separator=", "$) throws APIException { //parse inputs String resourcePath = "$method.resourcePath$"; resourcePath = resourcePath.replace("{format}","json"); String method = "$method.methodType$"; Map queryParams = new HashMap(); $if(!method.inputModel)$ $method.queryParameters:{ argument | if( $argument.name$ != null) { queryParams.put("$argument.name$", APIInvoker.toPathValue($argument.name$)); } }$ $method.pathParameters:{ argument | if( $argument.name$ != null) { resourcePath = resourcePath.replace("{$argument.name$}", $argument.name$); } }$ $endif$ $if(method.inputModel)$ $method.queryParameters:{ argument | if( $argument.inputModelClassArgument$ != null && $argument.methodNameFromModelClass$ != null) { queryParams.put("$argument.name$", $argument.methodNameFromModelClass$); } }$ $method.pathParameters:{ argument | if( $argument.inputModelClassArgument$ != null && $argument.methodNameFromModelClass$ != null) { resourcePath = resourcePath.replace("{$argument.name$}", $argument.methodNameFromModelClass$); } }$ $endif$ //make the API Call $if(method.postObject)$ String response = APIInvoker.invokeAPI(resourcePath, method, queryParams, postData); $endif$ $if(!method.postObject)$ String response = APIInvoker.invokeAPI(resourcePath, method, queryParams, null); $endif$ $if(!method.responseVoid)$ if(response == null || response.length() == 0){ return null; } $if(!method.returnValueList)$ //create output objects if the response has more than one object $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$>) APIInvoker.mapper.readValue(response, typeRef); return responseObject; } catch (IOException ioe) { String[] args = new String[]{response, typeRef.toString()}; throw new APIException(APIExceptionCodes.ERROR_CONVERTING_JSON_TO_JAVA, args, "Error in converting response json value to java object : " + ioe.getMessage(), ioe); } $endif$ $endif$ } }$ }