From 07e8b5ae0343dd2dbe4e4ffc74f9c308cf8cf8a3 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Fri, 15 Mar 2019 15:17:37 +0100 Subject: [PATCH] [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. --- .../openapi-generator/src/main/resources/go/client.mustache | 4 ++++ samples/client/petstore/go/go-petstore/client.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 6c05b5aec6d9..876fcb58ca35 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -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 diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index f45bf93f15c8..1da02b57f318 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -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