我正在使用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 次
- 1 回答
- 0 关注
- 305 浏览
添加回答
举报
0/150
提交
取消
