mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
124 lines
4.0 KiB
Smalltalk
124 lines
4.0 KiB
Smalltalk
package com.wordnik.api;
|
|
|
|
|
|
import com.wordnik.common.*;
|
|
import com.wordnik.common.ext.*;
|
|
import com.wordnik.model.*;
|
|
import com.wordnik.annotations.MethodArgumentNames;
|
|
import $exceptionPackageName$.APIExceptionCodes;
|
|
import $exceptionPackageName$.APIException;
|
|
|
|
import org.codehaus.jackson.map.DeserializationConfig.Feature;
|
|
import org.codehaus.jackson.map.ObjectMapper;
|
|
import org.codehaus.jackson.type.TypeReference;
|
|
|
|
import java.util.*;
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* NOTE: This class is auto generated by the drive code generator program so please do not edit the program manually.
|
|
* @author ramesh
|
|
*
|
|
*/
|
|
public class $resource$ extends $extends$ {
|
|
|
|
$methods:{ method |
|
|
/**
|
|
* $method.description$
|
|
$method.arguments:{ argument |
|
|
* @param $argument.name$ $argument.description$
|
|
$if(argument.allowedValues)$
|
|
* Allowed values are - $argument.allowedValues$
|
|
$endif$
|
|
}$
|
|
*
|
|
* @return $method.returnValue$ {@link $method.returnClassName$}
|
|
* @throws APIException $method.exceptionDescription$
|
|
*/
|
|
$if(method.hasArguments)$
|
|
@MethodArgumentNames(value="$method.argumentNames; separator=", "$")
|
|
$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");
|
|
String method = "$method.methodType$";
|
|
Map<String, String> queryParams = new HashMap<String, String>();
|
|
$if(!method.inputModel)$
|
|
$method.queryParameters:{ argument |
|
|
if( $argument.name$ != null) {
|
|
queryParams.put("$argument.name$", $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)$
|
|
$if(method.authToken)$
|
|
String response = invokeAPI(authToken, resourcePath, method, queryParams, postObject);
|
|
$endif$
|
|
$if(!method.authToken)$
|
|
String response = invokeAPI(null, resourcePath, method, queryParams, postObject);
|
|
$endif$
|
|
$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$
|
|
$endif$
|
|
|
|
//create output objects if the response has more than one object
|
|
$if(!method.responseVoid)$
|
|
if(response == null || response.length() == 0){
|
|
return null;
|
|
}
|
|
$if(!method.returnValueList)$
|
|
$method.returnValue$ responseObject = ($method.returnValue$)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);
|
|
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$
|
|
}
|
|
|
|
|
|
}$
|
|
}
|