forked from loafle/openapi-generator-original
Changes to Scala ResourceObject: (1) If return type is primitive, wrap it in option. (2) If APIInvoker returns null or raises 404 exception return None if primitive return or List() if collection.
This commit is contained in:
parent
a4e8a18fd6
commit
d4a8287a40
@ -62,8 +62,7 @@ $if(method.hasArguments)$
|
||||
$endif$
|
||||
|
||||
@throws(classOf[APIException])
|
||||
def $method.name$($method.argumentDefinitions; separator=", "$) $if(method.hasResponseValue)$:$method.returnValue$$endif$ = {
|
||||
|
||||
def $method.name$($method.argumentDefinitions; separator=", "$)$if(method.hasResponseValue)$: $if(method.returnValueList)$$method.returnValue$$else$Option[$method.returnValue$]$endif$$endif$ = {
|
||||
//parse inputs
|
||||
var resourcePath = "$method.resourcePath$".replace("{format}","json")
|
||||
val method = "$method.methodType$";
|
||||
@ -106,11 +105,20 @@ $method.pathParameters:{ argument |
|
||||
$endif$
|
||||
//make the API Call
|
||||
$if(method.hasResponseValue)$
|
||||
var response: String = null
|
||||
try {
|
||||
$if(method.postObject)$
|
||||
val response = apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams)
|
||||
response = apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams)
|
||||
$else$
|
||||
val response = apiInvoker.invokeAPI(resourcePath, method, queryParams, null, headerParams)
|
||||
response = apiInvoker.invokeAPI(resourcePath, method, queryParams, null, headerParams)
|
||||
$endif$
|
||||
} catch {
|
||||
case ex: APIException if ex.getCode == 404 =>
|
||||
$if(method.returnValueList)$ return List()
|
||||
$else$ return None
|
||||
$endif$
|
||||
case ex: APIException => throw ex
|
||||
}
|
||||
$else$
|
||||
$if(method.postObject)$
|
||||
apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams)
|
||||
@ -121,15 +129,22 @@ $endif$
|
||||
$if(!method.responseVoid)$
|
||||
|
||||
$if(method.hasResponseValue)$
|
||||
if(null == response || response.length() == 0){
|
||||
return null
|
||||
$if(!method.returnValueList)$
|
||||
if(null == response){
|
||||
return None
|
||||
}
|
||||
$endif$
|
||||
$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$]
|
||||
|
||||
$if(method.returnValueList)$
|
||||
responseObject
|
||||
$else$
|
||||
Some(responseObject)
|
||||
$endif$
|
||||
$endif$
|
||||
$endif$
|
||||
$if(method.returnValueList)$
|
||||
|
Loading…
x
Reference in New Issue
Block a user