OpenAPITools / OpenAPITools/openapi-generator
[BUG] `List<String>` not bound correctly in x-www-form-urlencoded POST requests (JavaSpring generator)
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 (example)?
- 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
Since #14449 was fixed, List<String> parameters are not mapped correctly in application/x-www-form-urlencoded requests (the controller receives a null value). @RequestPart does not work, but @RequestParam did.
openapi-generator version
6.4.0 (worked fine in 6.2.1).
OpenAPI declaration file content or url
See reproducer here: https://github.com/bjansen/openapi-generator/commit/a4f52bc0fd032b458b4e614eed74e19e761bcb21#diff-4a3bd04de4c3c2657007483855f41966b5bfc3336abacdc74e13ff838341173b
Relevant spec section:
paths:
/issue:
post:
operationId: reproduceIssue
consumes:
- application/x-www-form-urlencoded
parameters:
- in: body
name: body
schema:
type: "object"
properties:
listOfStrings:
type: "array"
items:
type: "string"
responses:
'200':
description: successful operation
Generation Details
./bin/generate-samples.sh ./bin/configs/spring-boot.yaml generates this mapping:
default ResponseEntity<Void> reproduceIssue(
@ApiParam(value = "") @Valid @RequestPart(value = "listOfStrings", required = false) List<String> listOfStrings
) {
...
The @RequestPart annotation does not bind the list correctly (see test in OpenApiGeneratorApplicationTests of the spring-boot server sample.
Steps to reproduce
Related issues/PRs
Suggest a fix
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 with the generated spring-boot server sample and its OpenApiGeneratorApplicationTests test, focusing on the reproduceIssue mapping for the application/x-www-form-urlencoded request. Reproduce the null List binding and compare the generated @RequestPart mapping with the previously working @RequestParam behavior. Done means the test passes with the list populated correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, backend, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100