diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index f1270b3c692d8..655bdc0938146 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -4,6 +4,7 @@ package {{packageName}} import ( "bytes" "context" + "encoding" "encoding/json" "encoding/xml" "errors" @@ -175,6 +176,14 @@ func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix stri parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) return } + if t, ok := obj.(encoding.TextMarshaler); ok { + data,err := t.MarshalText() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, string(data), collectionType) + return + } value = v.Type().String() + " value" case reflect.Slice: var indValue = reflect.ValueOf(obj) @@ -312,7 +321,7 @@ func (c *APIClient) prepareRequest( // add form parameters and file if available. if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(formFiles) > 0) { if body != nil { - return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + return nil, errors.New("cannot specify postBody and multipart form at the same time") } body = &bytes.Buffer{} w := multipart.NewWriter(body) @@ -353,7 +362,7 @@ func (c *APIClient) prepareRequest( if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { if body != nil { - return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + return nil, errors.New("cannot specify postBody and x-www-form-urlencoded form at the same time") } body = &bytes.Buffer{} body.WriteString(formParams.Encode()) @@ -518,7 +527,8 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err *s = string(b) return nil } - if f, ok := v.(*os.File); ok { + if _, ok := v.(*os.File); ok { + var f *os.File f, err = os.CreateTemp("", "HttpClientFile") if err != nil { return @@ -530,7 +540,8 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err _, err = f.Seek(0, io.SeekStart) return } - if f, ok := v.(**os.File); ok { + if _, ok := v.(**os.File); ok { + var f **os.File *f, err = os.CreateTemp("", "HttpClientFile") if err != nil { return @@ -555,7 +566,7 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err return err } } else { - return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + return errors.New("unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") } } else if err = json.Unmarshal(b, v); err != nil { // simple model return err @@ -628,7 +639,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e } if bodyBuf.Len() == 0 { - err = fmt.Errorf("invalid body type %s\n", contentType) + err = fmt.Errorf("invalid body type %s", contentType) return nil, err } return bodyBuf, nil