163 lines
5.7 KiB
Smalltalk

/**
* 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 $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.io.IOException
import scala.collection.mutable._
import scala.collection.JavaConversions._
$imports:{ import |
import $import$
}$
/**
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
* @author tony
*
*/
object $resource$ {
var apiInvoker:APIInvoker = null;
$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$
@throws(classOf[APIException])
def $method.name$($method.argumentDefinitions; separator=", "$) $if(method.hasResponseValue)$:$method.returnValue$$endif$ = {
//parse inputs
var resourcePath = "$method.resourcePath$".replace("{format}","json")
val method = "$method.methodType$";
var queryParams = new HashMap[String, String]
var headerParams = new HashMap[String, String]
$if(!method.inputModel)$
$method.queryParameters:{ argument |
if(null != $argument.name$) {
queryParams += "$argument.name$" -> APIInvoker.toPathValue($argument.name$)
}
}$
$method.headerParameters:{ argument |
if(null != $argument.name$) {
headerParams += "$argument.name$" -> APIInvoker.toPathValue($argument.name$)
}
}$
$method.pathParameters:{ argument |
if(null != $argument.name$) {
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.name$))
}
}$
$endif$
$if(method.inputModel)$
$method.queryParameters:{ argument |
if(null != $argument.inputModelClassArgument$ && null != $argument.methodNameFromModelClass$ ) {
queryParams += "$argument.name$" -> APIInvoker.toPathValue($argument.methodNameFromModelClass$)
}
}$
$method.headerParameters:{ argument |
if(null != $argument.inputModelClassArgument$ && null != $argument.methodNameFromModelClass$ ) {
headerParams += "$argument.name$" -> APIInvoker.toPathValue($argument.methodNameFromModelClass$)
}
}$
$method.pathParameters:{ argument |
if(null != $argument.inputModelClassArgument$ && null != $argument.methodNameFromModelClass$ ) {
resourcePath = resourcePath.replace("{$argument.name$}", APIInvoker.toPathValue($argument.methodNameFromModelClass$))
}
}$
$endif$
//make the API Call
$if(method.hasResponseValue)$
$if(method.postObject)$
val response = apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams)
$else$
val response = apiInvoker.invokeAPI(resourcePath, method, queryParams, null, headerParams)
$endif$
$else$
$if(method.postObject)$
apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams)
$else$
apiInvoker.invokeAPI(resourcePath, method, queryParams, null, headerParams)
$endif$
$endif$
$if(!method.responseVoid)$
$if(method.hasResponseValue)$
if(null == response || response.length() == 0){
return null
}
$endif$
$if(!method.returnValueList)$
$if(method.hasResponseValue)$
//create output objects if the response has more than one object
val responseObject = APIInvoker.deserialize(response, classOf[$method.returnClassName$]).asInstanceOf[$method.returnValue$]
responseObject
$endif$
$endif$
$if(method.returnValueList)$
val typeRef = new TypeReference[Array[$method.returnClassName$]] {}
try {
val responseObject = APIInvoker.mapper.readValue(response, typeRef).asInstanceOf[Array[$method.returnClassName$]]
responseObject.toList
} catch {
case ioe:IOException => {
val args = Array(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)
}
case _ => throw new APIException(APIExceptionCodes.ERROR_CONVERTING_JSON_TO_JAVA, "Error in converting response json value to java object")
}
$endif$
$endif$
}
}$
def getApiInvoker():APIInvoker = {
if(null == apiInvoker){
apiInvoker = APIInvoker.getApiInvoker();
}
return apiInvoker;
}
def setApiInvoker(invoker:APIInvoker) = {
apiInvoker = invoker;
}
}