forked from loafle/openapi-generator-original
[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:
parent
243ec9aa8e
commit
07e8b5ae03
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user