[BUG][Java | JaxRS-Jersey] Optional query parameter of type array generates (wrong) @DefaultValue
Created by: mtormento
Description
I have a query parameter defined as follows:
operationsQueryParam:
name: operations
description: Operations list
in: query
required: false
schema:
type: array
items:
type: string
This generates the following parameter:
@ApiParam(value = "Operations list", defaultValue="new java.util.ArrayList<String>()") @DefaultValue("new java.util.ArrayList<String>()") @QueryParam("operations") java.util.List<String> operations
I didn't set any default value for string item, so I would not expect the default value to be set. So I tried to make a request to my service omitting this optional parameter and the list contains:
List<String> operationsList = ["new java.util.ArrayList<String>()"]
So it becomes a list containing a single string: "new java.util.ArrayList()".
openapi-generator version
3.3.4
OpenAPI declaration file content or url
openapi: 3.0.0
paths:
/v1/examples:
get:
tags:
- Example
summary: Get a list of transactions
operationId: getFilteredTransactions
parameters:
- $ref: '#/components/parameters/operationsQueryParam'
...
components:
parameters:
operationsQueryParam:
name: operations
description: Operations list
in: query
required: false
schema:
type: array
items:
type: string
...
Command line used for generation
Maven execution
<configOptions>
<sourceFolder>api</sourceFolder>
<implFolder>impl</implFolder>
<hideGenerationTimestamp />
<!-- avoid to Generate impl files -->
<skipGenerateImplFiles>false</skipGenerateImplFiles>
<useBeanValidation>false</useBeanValidation>
<fullJavaUtil>true</fullJavaUtil>
</configOptions>
Steps to reproduce
See description ^^
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/1551 I think the issue is the same but it affects another generator.
Suggest a fix
I fixed it locally in queryParams mustache file by not adding a default value if a parameter is nullable.