首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swagger-Akka-Http:请求体中的对象列表

Swagger-Akka-Http:请求体中的对象列表
EN

Stack Overflow用户
提问于 2018-07-31 16:45:32
回答 1查看 649关注 0票数 0

我正在使用swagger-akka-http为我的Akka HTTP服务构建Swagger文档。

我的服务有一个接受CharacteristicList的POST方法。

代码语言:javascript
复制
@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
    }
  }

ApiImplicitParams中的dataTypeClass = classOf[List[Characteristic]]未按预期工作。在生成的Swagger YAML中有以下结果:

代码语言:javascript
复制
 parameters:
   - in: "body"
     name: "body"
     description: "Characteristics"
     required: true
     schema:
       type: "array"
       items:
         type: "object"

如何在请求体中记录一个对象集合?

EN

回答 1

Stack Overflow用户

发布于 2018-07-31 18:11:32

您可以这样做,接受post请求中的对象列表。

代码语言:javascript
复制
@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])

在你的邮寄路线上,你可以做这样的事情。

代码语言:javascript
复制
@Path("/student")
  @ApiOperation(
    value = "Returns student information POST request",
    nickname = "getStudentDetails",
    httpMethod = "POST",
    responseContainer = "List",
    code = 200,
    response = classOf[StudentDetails])
  @ApiImplicitParams(Array(
    new ApiImplicitParam(
      name = "body",
      required = true,
      dataType = "Request",
      paramType = "body")
  ))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51609144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档