[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.