我正在使用swagger-akka-http为我的Akka HTTP服务构建Swagger文档。
我的服务具有POST方法,接受List
中的Characteristic
。
@ApiOperation(value = "Fetch offerings by characteristics", httpMethod = "POST")
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "characteristics", required = true,
dataTypeClass = classOf[List[Characteristic]], paramType = "body")
))
@ApiResponses(Array(
new ApiResponse(code = 200, response = classOf[Offering], responseContainer = "List")
))
def fetchOfferings: Route = post {
entity(as[List[Characteristic]]) { characteristics =>
// some logic
}
}
dataTypeClass = classOf[List[Characteristic]]
中的 ApiImplicitParams
无法正常工作。生成的Swagger YAML中具有以下结果:
parameters:
- in: "body"
name: "body"
description: "Characteristics"
required: true
schema:
type: "array"
items:
type: "object"
如何在请求正文中记录一组对象?
答案 0 :(得分:0)
您可以这样操作,以在发布请求中接受对象列表。
queen
在发布路线上,您可以执行以下操作。
@ApiModel(value = "Request object")
case class Request(
@(ApiModelProperty@field)(
value = "Name",
name = "name",
required = true,
dataType = "string",
example = "DE",
allowEmptyValue = false)
name: String,
@(ApiModelProperty@field)(
value = "Marks",
name = "marks",
required = true,
dataType = "List[integer]",
example = "[10]",
allowEmptyValue = false)
marks: List[Int])