Skip to content

SetBody() does not support array of models #27

@guohuang

Description

@guohuang

Hi
I am a team member of Swagger CodeGen, we use the resty API, we recently ran into issue when setting body with an array of models, is it a known issue that resty does not allow passing array of objects in the body? below is the test exception:

--- FAIL: TestCreateUsersWithArrayInput (0.00s)
panic: interface conversion: interface is *[]petstore.User, not []uint8 [recovered]
    panic: interface conversion: interface is *[]petstore.User, not []uint8

goroutine 18 [running]:
testing.tRunner.func1(0xc8200f6090)
    /usr/local/go/src/testing/testing.go:450 +0x171
github.com/go-resty/resty.DetectContentType(0x2e9320, 0xc8200fe140, 0x0, 0x0)
    /Users/xx/go/src/github.com/go-resty/resty/client.go:780 +0xd6
github.com/go-resty/resty.handleRequestBody(0xc8200bc000, 0xc82010a000, 0x0, 0x0)
    /Users/xx/go/src/github.com/go-resty/resty/middleware.go:295 +0xc4
github.com/go-resty/resty.parseRequestBody(0xc8200bc000, 0xc82010a000, 0x0, 0x0)
    /Users/xx/go/src/github.com/go-resty/resty/middleware.go:107 +0x245
github.com/go-resty/resty.(*Client).execute(0xc8200bc000, 0xc82010a000, 0x0, 0x0, 0x0)
    /Users/xx/go/src/github.com/go-resty/resty/client.go:579 +0xc7
github.com/go-resty/resty.(*Request).Execute(0xc82010a000, 0x40ab28, 0x4, 0xc8200f2240, 0x32, 0x4, 0x0, 0x0)
    /Users/xx/go/src/github.com/go-resty/resty/request.go:394 +0x105
github.com/go-resty/resty.(*Request).Post(0xc82010a000, 0xc8200f2240, 0x32, 0x4

FYI, with the same code, single object works perfectly.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions