[BUG] Wrong parameter for multipart-form-data file upload when using java reactive
Created by: bit-factor
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
I want to build a rest-service which needs to be able to support large-ish file uploads. I am using spring-boot 2.2.7.RELEASE with webflux.
openapi-generator version
openapi-generator-maven-plugin
v4.3.1.
OpenAPI declaration file content or url
/upload/{parentId}/doc:
post:
tags:
- docs
summary: uploads a new document
operationId: upload.doc
security:
- bearerAuth: []
parameters:
- in: path
name: parentId
schema:
type: string
required: true
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
responses:
201:
description: upload was succesfull
Command line used for generation
I am using it directly in my pom.xml
file as follows:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
<modelPackage>com.application.rest.models</modelPackage>
<apiPackage>com.application.rest</apiPackage>
<library>spring-boot</library>
<generatorName>spring</generatorName>
<modelNamePrefix>Rest</modelNamePrefix>
<generateSupportingFiles>true</generateSupportingFiles>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<serializableModel>true</serializableModel>
<invokerPackage>com.application</invokerPackage>
<basePackage>com.application.backend</basePackage>
<configPackage>com.application.conf</configPackage>
<dateLibrary>java8</dateLibrary>
<delegatePattern>false</delegatePattern>
<useOptional>true</useOptional>
<sourceFolder>src/main/java</sourceFolder>
<reactive>true</reactive>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
In the maven-java directory, simply run mvn clean compile
.
Related issues/PRs
- https://github.com/OpenAPITools/openapi-generator/issues/6677 -- uses react/java, but doesn't refer to file-upload, it looks for a way to make the parameter optional;
Suggest a fix
The correct parameter should be Flux<Part>
or Flux<FilePart>
. There are several examples:
- https://dzone.com/articles/step-by-step-procedure-of-spring-webflux-multipart
- https://medium.com/@eaimanshoshi/step-by-step-procedure-of-spring-webflux-multipart-file-upload-and-read-each-line-without-saving-it-6a12be64f6ee
Simply using MultipartFile
forces us to go through InputStream and then handle blocking calls (like close
, for instance) from non-blocking code.