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
  • #4866
Closed
Open
Issue created Dec 24, 2019 by Administrator@rootContributor

[BUG][JAVA][JAX-RS Jersey 2] Generated api for a Post with multipart/form-data is not able to upload file

Created by: ericpetrowiakjelli

Bug Report Checklist

  • [ X] Have you provided a full/minimal spec to reproduce the issue?
  • [ X] Have you validated the input using an OpenAPI validator (example)?
  • [ X] What's the version of OpenAPI Generator used?
  • [ X] Have you search for related issues/PRs?
  • [ X] What's the actual output vs expected output?
Description

I am trying to use an api request to upload an audio file using a multipart Post request, but it appears that with the given yaml, the body is always null and therefore won't serialize my form data.

openapi-generator version

4.1.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Mine
  description: An Example API
  license:
    name: proprietary
  version: "1.0"
servers:
- url: /api
  description: HERE
paths:
/audioMedia:
 post:
      operationId: uploadAudio
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  $ref: '#/components/schemas/FormDataBodyPart'
      responses:
        default:
          description: default response
          content:
            application/json;charset=utf-8:
              schema:
                $ref: '#/components/schemas/AudioMedia'
Command line used for generation

Used maven plugin:

<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>mine.yaml</inputSpec>
                            <generatorName>java</generatorName>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                            <modelPackage>com.mine.httpClient.model</modelPackage>
                            <apiPackage>com.mine.httpClient.api</apiPackage>
                            <skipValidateSpec>true</skipValidateSpec>
                            <addCompileSourceRoot>true</addCompileSourceRoot>

                            <configOptions>
                                <GenerateOpenAPIMetadata>false</GenerateOpenAPIMetadata>
                                <sourceFolder>src/main/java</sourceFolder>
                                <dateLibrary>legacy</dateLibrary>
                            </configOptions>
                            <library>jersey2</library>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Run openapi-generator-maven-plugin to generate api from yaml. Use the generated client to try and upload the file. The logging (when debugging is on) does not show any multipart form data being passed in the request

Suggest a fix

In my case, I am not passing a requestBody in this Post request. It looks like the generated client invokeApi method requires (body != null) to even serialize the form data and content type. So due to this, it looks like nothing is being passed into the request.

Assignee
Assign to
Time tracking