[BUG][GO] multipart should default to JSON
Created by: thiagoarrais
Description
Generated go client does not serialize arrays of complex objects inside multipart request body as JSON.
openapi-generator version
master: 3526fe40
OpenAPI declaration file content or url
https://gist.github.com/thiagoarrais/fcf16a1fac605229fa62d376974a7513
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -i /local/petstore.yaml -g go -o /local/out
Steps to reproduce
- Generate golang client using command line above
- Write sample main.go that uses the generated client:
package main
import (
"context"
"openapi"
"github.com/antihax/optional"
)
func main() {
apiConfig := openapi.NewConfiguration()
apiConfig.BasePath = "http://localhost:8000"
apiclient := openapi.NewAPIClient(apiConfig)
opts := openapi.CreatePetsOpts {
Pets: optional.NewInterface([]openapi.Pet {
{Id: 0, Name: "zero"},
{Id: 1, Name: "one"},
}),
};
_, err := apiclient.PetsApi.CreatePets(context.Background(), &opts);
if err != nil {
panic(err)
}
}
- Check that POST contents are not valid JSON:
--a35b78e52bc7dc03dd1be4e2692cc126d8b68aa7ab2fac8b3da67bf11554
Content-Disposition: form-data; name="pets"
{0,zero},{1,one}
--a35b78e52bc7dc03dd1be4e2692cc126d8b68aa7ab2fac8b3da67bf11554--
should be (as per OpenAPI spec)
--6ddd609cb3d9b792d70600dc1202811b24f5bc1b363f7503300d24763283
Content-Disposition: form-data; name="pets"
[{"name":"zero"},{"id":1,"name":"one"}]
--6ddd609cb3d9b792d70600dc1202811b24f5bc1b363f7503300d24763283--
Related issues/PRs
Couldn't find
Suggest a fix
PR incoming! :-p