英文:
How do I write a swagger endpoint using go-swagger where I can delay the consumption of the body in its parameters?
问题
我需要定义一个 Swagger 端点,该端点需要接受文本和 ZIP 格式的媒体类型。在生成的包中,是否可以直接传递 io.ReadCloser 而不是将其重新分配到不同的类型(如字符串)中?
英文:
I need to define a swagger endpoint that needs to take in media types text and zip. Instead of having the generated package consume it and reassign it into separate types such as string, can I get the io.Readcloser passed through directly?
答案1
得分: 1
Swagger规范:
"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
}
英文:
Swagger spec:
"parameters": [
{
"name": "foo",
"in": "body",
"schema": {
"type": string,
"format": "binary"
}
}
]
Generated parameter:
type SomeParams struct {
Foo io.ReadCloser
}
And in the generated BindRequest
method, the request body ReadCloser is assigned to the Foo
field:
if runtime.HasBody(r) {
o.Foo = r.Body
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论