Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2964
Closed
Open
Issue created May 21, 2019 by Administrator@rootContributor

[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
  1. Generate golang client using command line above
  2. 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)
    }
}
  1. 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

Assignee
Assign to
Time tracking