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
  • #10213
Closed
Open
Issue created Aug 20, 2021 by Administrator@rootContributor

[BUG][JavaSpring] Model classes attempt to use java.util.Arrays without importing it

Created by: anno1985

Bug Report Checklist

Description

The pojo.mustache template seems to attempt to use the Arrays class (four times) if #vendorExtensions.x-jackson-optional-nullable-helpers is set. However, the model.mustache doesn't seem to import java.util.Arrays;.

This results in a failing build at compile time (here with maven):

[ERROR] /path/to/target/generated-sources/openapi/src/gen/java/com/example/generated/model/MyModel.java:[100, 114] cannot find symbol
[ERROR]   symbol:   variable Arrays
[ERROR]   location: class com.example.generated.model.MyModel

The issue appears when using openapi-generator-maven-plugin:5.2.1

Suggest a fix

I'm not familiar with mustache syntax, but I'm guessing adding something similar to the following to model.mustache around line 32 should do the trick:

{{^isEnum}}
{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
import java.util.Arrays;
{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
{{/isEnum}}

Alternatively, the respective code lines in pojo.mustache could be changed to use the fully qualified class name, java.util.Arrays instead of just Arrays (on lines 135, 142, 147 and 155).

Note that I haven't verified if the import is actually added correctly already if isByteArray is set, in which case changes to lines 135 and 147 would be superfluous (and the first option, changes to imports, might be preferable to sometimes fully qualifying the class and sometimes (when dealing with ByteArrays) relying on imports).

Assignee
Assign to
Time tracking