[go] support decoding plain string responses (#2414)

For the following spec:

``` yaml
      responses:
        "200":
          description: Pong.
          content:
            text/plain:
              schema:
                type: string
```

The generated client currently fails with `undefined response type`.

In this scenario, `v interface{}` is a string pointer which can be
populated regardless of the content-type.
This commit is contained in:
Bilal Amarni 2019-03-15 15:17:37 +01:00 committed by William Cheng
parent 243ec9aa8e
commit 07e8b5ae03
2 changed files with 8 additions and 0 deletions

View File

@ -317,6 +317,10 @@ func (c *APIClient) prepareRequest(
}
func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
if s, ok := v.(*string); ok {
*s = string(b)
return nil
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err

View File

@ -328,6 +328,10 @@ func (c *APIClient) prepareRequest(
}
func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
if s, ok := v.(*string); ok {
*s = string(b)
return nil
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err