OpenAPITools / OpenAPITools/openapi-generator
[BUG] type: array is not taken into account when content is multipart/form-data
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
type: array is not taken into account when content is multipart/form-data
generated java code:
@ApiOperation(value = "upload files", nickname = "uploadFiles", notes = "", response = UploadActionStatus.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "files upload status", response = UploadActionStatus.class),
@ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
@RequestMapping(value = "/utility/upload",
produces = { "application/json" },
consumes = { "multipart/form-data" },
method = RequestMethod.POST)
default ResponseEntity<UploadActionStatus> _uploadFiles(@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile filenames) {
return uploadFiles(filenames);
}
Expected:
@ApiOperation(value = "upload files", nickname = "uploadFiles", notes = "", response = UploadActionStatus.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "files upload status", response = UploadActionStatus.class),
@ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
@RequestMapping(value = "/utility/upload",
produces = { "application/json" },
consumes = { "multipart/form-data" },
method = RequestMethod.POST)
default ResponseEntity<UploadActionStatus> _uploadFiles(@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile[] filenames) {
return uploadFiles(filenames);
}
openapi-generator version
openapi-generator-maven-plugin 4.2.2
OpenAPI declaration file content or url
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
filenames:
type: array
items:
type: string
format: binary
Command line used for generation
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.directory}/integration/my.yml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>my..controller</apiPackage>
<modelPackage>my..model</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<configOptions>
<enableBuilderSupport>true</enableBuilderSupport>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<serializableModel>true</serializableModel>
<delegatePattern>true</delegatePattern>
<useBeanValidation>true</useBeanValidation>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<simpleFluentPattern>true</simpleFluentPattern>
<collectionFluentPattern>true</collectionFluentPattern>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
create java maven project and generate code
Related issues/PRs
Suggest a fix/enhancement
Expected:
filenames shall be an array:
@ApiOperation(value = "upload files", nickname = "uploadFiles", notes = "", response = UploadActionStatus.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "files upload status", response = UploadActionStatus.class),
@ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
@RequestMapping(value = "/utility/upload",
produces = { "application/json" },
consumes = { "multipart/form-data" },
method = RequestMethod.POST)
default ResponseEntity<UploadActionStatus> _uploadFiles(@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile[] filenames) {
return uploadFiles(filenames);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided Maven configuration, OpenAPI declaration, and spring generator. Trace multipart/form-data request-body handling for an array of binary items, then verify generation produces a MultipartFile[] parameter rather than MultipartFile for the filenames field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100