OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin-spring] Multipart with JSON array broken
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The following schema for a multi-part request consists of an array of strings and a binary file:
paths:
/jobs/new:
post:
summary: Post a new job request
requestBody:
content:
'multipart/form-data':
schema:
type: object
properties:
commandLine:
type: array
items:
type: string
workspaceTree:
type: string
format: binary
The expectation is that each of the parts are processed according to their provided content-type. For the array part however, if a request is prepared using 'applicatin/json' as content-type, the parsed array is treatead as a comma-separated string and the result is wrong.
The generated interface is:
@RequestMapping(
method = [RequestMethod.POST],
value = ["/jobs/new"],
produces = ["application/json"],
consumes = ["multipart/form-data"]
)
fun jobsNewPost( @Valid @RequestParam(value = "commandLine", required = true) commandLine: kotlin.collections.List<kotlin.String> , @Valid @RequestPart("workspaceTree", required = false) workspaceTree: org.springframework.web.multipart.MultipartFile?): ResponseEntity<java.util.UUID> {
where the commandLine parameters is annotated with RequestParam instead of RequestPart. Changing this annotation manually makes it work.
openapi-generator version
7.13
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
I suspect that the fix should make sure that all parts are annotated with RequestPart, but I don't know if there are exceptions to this.
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
Start by generating the Kotlin Spring interface from the supplied multipart/form-data schema and inspect how the commandLine array is mapped. The fix is complete when the array part is generated with RequestPart rather than RequestParam and is processed as JSON instead of a comma-separated string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, 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