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
  • #2772
Closed
Open
Issue created Apr 30, 2019 by Administrator@rootContributor

[GOLANG][client] Missing form-data boundary

Created by: 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()

Assignee
Assign to
Time tracking