Skip to content

[GOLANG][client] Missing form-data boundary #2772

Closed
@thiagoarrais

Description

@thiagoarrais
Description

Generated go client does not include the boundary parameter in the multipart/form-data content type. Tested with javascript client and it behaves well.

openapi-generator version

4.0.0-SNAPSHOT, 3.3.4

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Images API
  version: 1.0.0
servers:
  - url: http://api.example.com/v1
paths:
  /images:
    post:
      operationId: publishImage
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                name:
                  type: string
                contents:
                  type: string
                  format: byte
      responses:
        '201':
          description: Image ID
          content:
            application/json:
              schema: 
                type: object
                properties:
                  id:
                    type: string 
Command line used for generation

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -i /local/openapi.yml -g go -o /local/out

Steps to reproduce
  1. Generate golang client using command line above
  2. Write sample main.go that used the generated client:
// main.go
package main

import (
	"context"
  "openapi"
	"github.com/antihax/optional"
)

func main() {
    apiConfig := openapi.NewConfiguration()
    apiConfig.BasePath = "http://localhost:8000"

    apiclient := openapi.NewAPIClient(apiConfig)

    imageOpts := openapi.PublishImageOpts {
      Name: optional.NewString("my-image"),
      Contents: optional.NewString("my-image-data"),
    };

    _, _, err := apiclient.DefaultApi.PublishImage(context.Background(), &imageOpts);
    if err != nil {
      panic(err)
    }
}
  1. Start local server at port 8000
  2. Run sample code
  3. Check that received Content-Type header does not include boundary info:
Content-Type: multipart/form-data

--c7fc9b6b9e
Content-Disposition: form-data; name="name"

my-image

should be

Content-Type: multipart/form-data; boundary: c7fc9b6b9e

--c7fc9b6b9e
Content-Disposition: form-data; name="name"

my-image
Related issues/PRs

Couldn't find

Suggest a fix/enhancement

In prepareRequest, when the content type is multipart/form-data, it should be augmented with info from multipart.Writer.Boundary()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions