亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 230 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號