我正在使用swagger来记录我的Play-Scala应用程序。
我的控制器如下:
@Api(value = "/people")
class PersonController {
import JsonFormats._
@ApiOperation(response = ?????, responseContainer = "Array", httpMethod = "GET")
def showPeople(...) = Action {
// Code here..to get persons of type List[Person]
val json: JsObject = Json.obj("people" -> persons)
Ok(json)
}
}
我的JsonFormats.scala如下:
object JsonFormats {
implicit val personFormat = new Format[Person] {
def writes(person: Person): JsValue = {
Json.obj(
"fName" -> person.name.fName,
"lName" -> person.name.lName,
"age" -> person.age)
}
}
我的模型类如下
case class Person(name: Name, age: String) {
gender: String
}
case class Name {
fName: String,
lName: String,
}
问题:在我的控制器中@ ApiOperation的响应参数中指定什么,因此它在swagger-ui中显示json响应结构作为预期格式(如下所示)。
{
"people":[
{
"fName":"",
"lName":"",
"age":""
}
]
}
答案 0 :(得分:3)
这样做的样本:
@ApiOperation( value = "Get a content type by its name", notes = "Returns a content type", response = classOf[models.ContentType], httpMethod = "GET" ) @ApiResponses(Array( new ApiResponse(code = 404, message = "Content Type not found") ))
在这种情况下,models.ContentType是案例类。
干杯