2

我正在输入使用 go-swagger 生成路径参数。但是运行后swagger generate spec -o ./swagger.yaml --scan-models我看到生成的招摇有in:query而不是in:path

包装类型

package types

type URCapID struct {
    Vendor  string `yaml:"vendorID" json:"vendorID" mapstructure:"vendorID"`
    ID      string `yaml:"urcapID" json:"urcapID" mapstructure:"urcapID"`
    Version string `yaml:"version" json:"version" mapstructure:"version"`
}

手柄功能

// swagger:parameters deleteURCap
type urcapIDParam struct {
    // The id of the urcap to uninstall/delete
    // in: path
    // required: true
    types.URCapID
}

// Uninstall and deletes urcap if installed
func Uninstall(w http.ResponseWriter, r *http.Request) {

    //  swagger:route DELETE /urcap/{vendorID}/{urcapID}/{version} URCap deleteURCap
    //
    //  Delete/Uninstall URCap if installed.
    //
    //      Consumes:
    //      - application/json
    //
    //      Produces:
    //      - application/json
    //
    //      Schemes: http
    //
    //      Responses:
    //          201: noContent

}

自动生成的 swagger.yaml

/urcap/{vendorID}/{urcapID}/{version}:
    delete:
      consumes:
      - application/json
      operationId: deleteURCap
      parameters:
      - in: query
        name: vendorID
        type: string
        x-go-name: Vendor
      - in: query
        name: urcapID
        type: string
        x-go-name: ID
      - in: query
        name: version
        type: string
        x-go-name: Version
      produces:
      - application/json
      responses:
        "201":
          $ref: '#/responses/noContent'
      schemes:
      - http
      summary: Delete/Uninstall URCap if installed.
      tags:
      - URCap
4

0 回答 0