fixed response type with array of simple types

This commit is contained in:
Tony Tam 2013-09-12 13:41:53 -07:00
parent 56d5167a27
commit a140ea2b9d

View File

@ -237,19 +237,35 @@ object SwaggerSerializers {
class OperationSerializer extends CustomSerializer[Operation](implicit formats => ({ class OperationSerializer extends CustomSerializer[Operation](implicit formats => ({
case json => case json =>
val responseClass = (json \ "items") match { val t = SwaggerSerializers.jsonSchemaTypeMap.getOrElse(
case e: JObject => { ((json \ "type").extractOrElse(""), (json \ "format").extractOrElse(""))
, (json \ "type").extractOrElse(""))
val inner = { val inner = {
(e \ "type").extractOrElse({ val items = new scala.collection.mutable.HashSet[String]
(e \ "$ref").extract[String] val map = new scala.collection.mutable.HashMap[String, String]
}) (json \ "items") match {
case JObject(e) => {
for(a <- e) {
a._2 match {
case e: JString => map += a._1 -> e.s
case _ =>
} }
"%s[%s]".format((json \ "type").extract[String], inner)
} }
case _ => (json \ "type").extractOrElse({ val `type` = map.getOrElse("type", "")
!!(json, OPERATION, "responseClass", "missing required field", ERROR) val format = map.getOrElse("format", "")
"" if(map.contains("$ref")) {
}) Some(map("$ref"))
}
else
Option(jsonSchemaTypeMap.getOrElse((`type`,format), `type`))
}
case _ => None
}
}
val responseClass = inner match {
case Some(a) => "%s[%s]".format(t, a)
case _ => t
} }
Operation( Operation(