0

我需要定义一个需要接受媒体类型 text 和 zip 的 swagger 端点。我可以让 io.Readcloser 直接通过,而不是让生成的包使用它并将其重新分配为单独的类型(例如字符串)吗?

4

1 回答 1

1

招摇规格:

"parameters": [
  {
    "name": "foo",
    "in": "body",
    "schema": {
      "type": string,
      "format": "binary"
    }
  }
]

生成的参数:

type SomeParams struct {
    Foo io.ReadCloser
}

并且在生成的BindRequest方法中,请求体 ReadCloser 被赋给了该Foo字段:

    if runtime.HasBody(r) {
        o.Foo = r.Body
    }
于 2022-02-09T04:11:00.160 回答