OpenAPITools / OpenAPITools/openapi-generator
[Bug][Java][Spring] Dynamic query parameters with multiple values generates wrong type
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
With additionalProperties and explode it's possible to allow dynamic query parameters with multiple values. The spring generator creates a Map<String, List<String>> for it. Spring supports such query parameters since Spring 3.x but it needs a MultiValueMap.
openapi-generator version
4.3.1
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: BugExample.yml
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
'/users':
parameters:
- name: filters
in: query
required: true
schema:
type: object
additionalProperties:
type: array
items:
type: string
example:
firstName:
- Alice
lastName:
- Smith
- Jones
style: form
explode: true
get:
summary: Get all users matching the filter
responses:
'200':
description: Users Found
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
examples:
Get Users:
value:
- id: 142
firstName: Alice
lastName: Smith
email: alice.smith@gmail.com
dateOfBirth: '1997-10-31'
emailVerified: true
signUpDate: '2019-08-24'
- id: 123
firstName: Alice
lastName: Jones
email: alice.jones@gmail.com
dateOfBirth: '1997-10-30'
emailVerified: true
signUpDate: '2019-08-25'
operationId: get-users-filtered
description: Retrieve all users matching the filters.
components:
schemas:
User:
title: User
type: object
description: ''
examples:
- id: 142
firstName: Alice
lastName: Smith
email: alice.smith@gmail.com
dateOfBirth: '1997-10-31'
emailVerified: true
signUpDate: '2019-08-24'
properties:
id:
type: integer
description: Unique identifier for the given user.
firstName:
type: string
lastName:
type: string
email:
type: string
format: email
dateOfBirth:
type: string
format: date
example: '1997-10-31'
emailVerified:
type: boolean
description: Set to true if the user's email has been verified.
createDate:
type: string
format: date
description: The date that the user was created.
required:
- id
- firstName
- lastName
- email
- emailVerified
Command line used for generation
OpenAPI Generator maven plugin:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.1</version>
<executions>
<!-- Fake Source API -->
<execution>
<id>fake-source-service</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- specify the openapi yaml -->
<inputSpec>${project.basedir}/src/main/resources/openapi/api/example.yml
</inputSpec>
<!-- target to generate java server code -->
<generatorName>spring</generatorName>
<apiPackage>eu.wiegandt.OpenApiMultiValueParamBugExample.api</apiPackage>
<modelPackage>eu.wiegandt.OpenApiMultiValueParamBugExample.model</modelPackage>
<invokerPackage>eu.wiegandt.OpenApiMultiValueParamBugExample.invoker</invokerPackage>
<packageName>eu.wiegandt.OpenApiMultiValueParamBugExample.server</packageName>
<!-- pass any necessary config options -->
<configOptions>
<serializableModel>true</serializableModel>
<snapshotVersion>true</snapshotVersion>
<delegatePattern>true</delegatePattern>
<useBeanValidation>false</useBeanValidation>
<performBeanValidation>false</performBeanValidation>
<dateLibrary>java8</dateLibrary>
<useTags>false</useTags>
</configOptions>
<!-- prevent generation of unnecessary files -->
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>true</generateSupportingFiles>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<additionalProperties>removeEnumValuePrefix=false</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Generate
- Send multiple parameters with same name
Expected:
All values recieved.
Actual:
Only the first value is recieved.
Example
Here is a GitHub Project with a full working example including a test which shows the described problem:
https://github.com/Nicklas2751/OpenApiMultiValueParamBugExample
Suggest a fix/enhancement
Instead of Map<String,List<String>> uses MultiValueMap.
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 running the linked OpenApiMultiValueParamBugExample project and its reproduction test, then inspect the Spring generator output produced by the Maven plugin. Confirm that repeated query parameters preserve all values and that the generated parameter type supports them as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100