Generate classes from the models declared in 'responseModel'

* ResponseMessage has new constructor parameter, an optional string for responseModel
* Make sure we add it to list of models
* make sure the responseModel is part of the error list available to mustache
This commit is contained in:
Rob Blair 2013-11-18 17:30:15 -08:00
parent 11bede2b7d
commit 2dc6b485e0
3 changed files with 8 additions and 4 deletions

View File

@ -227,10 +227,12 @@ class Codegen(config: CodegenConfig) {
var bodyParamRequired: Option[String] = Some("true")
if (operation.responseMessages != null) {
operation.responseMessages.foreach(param => {
operation.responseMessages.foreach(param => {
val params = new HashMap[String, AnyRef]
params += "code" -> param.code.toString()
params += "reason" -> param.message
if (!param.responseModel.isEmpty)
params += "responseModel" -> param.responseModel
params += "hasMore" -> "true"
errorList += params
})

View File

@ -222,12 +222,14 @@ object SwaggerSerializers {
case json =>
ResponseMessage(
(json \ "code").extractOrElse(0),
(json \ "message").extractOrElse("")
(json \ "message").extractOrElse(""),
(json \ "responseModel").extractOpt[String]
)
}, {
case x: ResponseMessage =>
("code" -> x.code) ~
("message" -> x.message)
("message" -> x.message) ~
("responseModel" -> x.responseModel)
}
))

View File

@ -35,7 +35,7 @@ object CoreUtils {
def extractModelNames(op: Operation): Set[String] = {
// // POST, PUT, DELETE body
val modelNames = Set(op.responseClass) ++ op.parameters.filter(_.paramType == "body").map(_.dataType)
val modelNames = Set(op.responseClass) ++ op.parameters.filter(_.paramType == "body").map(_.dataType) ++ op.responseMessages.filter(!_.responseModel.isEmpty).map(_.responseModel.get)
modelNames map extractBasePartFromType
}