From 1ccf4b9cb3a2877f7ec8a2e59fe0916601b64aa7 Mon Sep 17 00:00:00 2001 From: dukov Date: Tue, 19 Nov 2019 19:20:15 -0800 Subject: [PATCH] [Go] Bypass object decode in case of empty body (#4546) Fixes #4545 Change-Id: Ic724843713f60f996ed72326ad6ef6762ec2e713 --- .../src/main/resources/go-experimental/client.mustache | 3 +++ .../openapi-generator/src/main/resources/go/client.mustache | 3 +++ samples/client/petstore/go/go-petstore-withXml/client.go | 3 +++ samples/client/petstore/go/go-petstore/client.go | 3 +++ 4 files changed, 12 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/go-experimental/client.mustache b/modules/openapi-generator/src/main/resources/go-experimental/client.mustache index ec129d3d432..cefd6c7c409 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/client.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/client.mustache @@ -339,6 +339,9 @@ func (c *APIClient) prepareRequest( } func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } if s, ok := v.(*string); ok { *s = string(b) return nil diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index ec129d3d432..cefd6c7c409 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -339,6 +339,9 @@ func (c *APIClient) prepareRequest( } func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } if s, ok := v.(*string); ok { *s = string(b) return nil diff --git a/samples/client/petstore/go/go-petstore-withXml/client.go b/samples/client/petstore/go/go-petstore-withXml/client.go index 73bf022c888..490d804736f 100644 --- a/samples/client/petstore/go/go-petstore-withXml/client.go +++ b/samples/client/petstore/go/go-petstore-withXml/client.go @@ -351,6 +351,9 @@ func (c *APIClient) prepareRequest( } func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } if s, ok := v.(*string); ok { *s = string(b) return nil diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index c73a8db8d09..343078e15cd 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -350,6 +350,9 @@ func (c *APIClient) prepareRequest( } func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } if s, ok := v.(*string); ok { *s = string(b) return nil