Skip to content

Commit

Permalink
meh
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Kaiser committed Mar 25, 2024
1 parent f191904 commit 32b35bc
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions modules/openapi-generator/src/main/resources/go/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package {{packageName}}
import (
"bytes"
"context"
"encoding"
"encoding/json"
"encoding/xml"
"errors"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 32b35bc

Please sign in to comment.