Merge pull request #51 from spatex/master

fixes for error messages in Java/JaxRS generated code
This commit is contained in:
Tony Tam 2013-05-06 12:46:18 -07:00
commit d30441dd27
2 changed files with 23 additions and 2 deletions

View File

@ -20,8 +20,10 @@ public class {{className}} {
@{{httpMethod}}
@Path("{{path}}")
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", responseClass = "{{{returnType}}}")
@ApiErrors(value = { @ApiError(code = 400, reason = "Invalid ID supplied"),
@ApiError(code = 404, reason = "Pet not found") })
@ApiErrors(value = { {{#errorList}} @ApiError(code = {{{code}}}, reason = "{{{reason}}}"){{#hasMore}},{{/hasMore}}
{{/errorList}}
})
public Response {{nickname}}(
{{#allParams}}
{{#queryParameter}}

View File

@ -81,10 +81,12 @@ class Codegen(config: CodegenConfig) {
lb
})
opList += apiToMap(apiPath, operation)
CoreUtils.extractModelNames(operation).foreach(i => allImports += i)
}
})
}
case None =>
}
@ -206,6 +208,18 @@ class Codegen(config: CodegenConfig) {
val headerParams = new ListBuffer[AnyRef]
val bodyParams = new ListBuffer[AnyRef]
var paramList = new ListBuffer[HashMap[String, AnyRef]]
var errorList = new ListBuffer[HashMap[String, AnyRef]]
if (operation.errorResponses != null) {
operation.errorResponses.foreach(param => {
val params = new HashMap[String, AnyRef]
params += "code" -> param.code.toString()
params += "reason" -> param.reason
params += "hasMore" -> "true"
errorList += params
})
}
if (operation.parameters != null) {
operation.parameters.foreach(param => {
@ -284,6 +298,10 @@ class Codegen(config: CodegenConfig) {
case 0 =>
case _ => pathParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
}
errorList.size match{
case 0 =>
case _ => errorList.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
}
val sp = {
val lb = new ListBuffer[AnyRef]
@ -325,6 +343,7 @@ class Codegen(config: CodegenConfig) {
"queryParams" -> queryParams.toList,
"headerParams" -> headerParams.toList,
"requiredParams" -> requiredParams.toList,
"errorList" -> errorList,
"httpMethod" -> operation.httpMethod.toUpperCase,
operation.httpMethod.toLowerCase -> "true")
if (requiredParams.size > 0) properties += "requiredParamCount" -> requiredParams.size.toString