Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2600
Closed
Open
Issue created Apr 04, 2019 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking