为了账号安全,请及时绑定邮箱和手机立即绑定

go-swagger - 请求正文中的对象数组

go-swagger - 请求正文中的对象数组

Go
慕田峪9158850 2022-12-19 10:34:50
我正在使用go-swagger为我们的 API 生成 swagger 文件我的请求在 JSON 格式中看起来像这样:{  [    {      "name": "title1",      "label": "tag1",      "sort": true    },    {      "name": "title2",      "label": "tag2",      "sort": true    }  ]}这就是我现在的评论// swagger:route POST /admin/qc QC createQC//// Creates a new QC.//////     Consumes://     - application/json////     Produces://     - application/json////     Schemes: https////     Deprecated: false//////     Parameters://       + name: Authorization//         in: header//         required: true//         type: string////       + name: input//         in: body//         required: true//         type: array//         items: QC////     Responses://       200: StatusOK这是生成的 swagger 文件/admin/qc:    post:      consumes:      - application/json      operationId: createQC      parameters:      - in: header        name: Authorization        required: true        type: string      - in: body        name: input        required: true        schema:          type: array      produces:      - application/json      responses:        "200":          description: StatusOK          schema:            $ref: '#/definitions/StatusOK'      schemes:      - https      summary: Creates a new QC.      tags:      - QCgo-swagger 不会选择此注释中的项目类型。不幸的是,更改此 API 的请求类型的选项不可用。有人知道我应该如何注释吗?
查看完整描述

1 回答

?
收到一只叮咚

TA贡献1821条经验 获得超5个赞

为了注释这种类型的请求,您需要像这样定义一个新结构:


// swagger:parameters createQC

type CreateQCReqs struct {

    // in: body

    Body []*CreateQCReq

}

swagger:parameters你需要用api的操作id来注释它

之后你需要用你想要的数据类型定义Body字段在我的例子中它是一个数组CreateQCReq

之后你需要删除你的body参数swagger:route,否则body字段在您的 swagger 文件将生成 2 次


查看完整回答
反对 回复 2022-12-19
  • 1 回答
  • 0 关注
  • 305 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号