'How do I write a swagger endpoint using go-swagger where I can delay the consumption of the body in its parameters?

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?



Solution 1:[1]

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
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lencharest