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
  • #5920
Closed
Open
Issue created Apr 13, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][JAVA] Referencing Object with additionalProperties fails to compile with incorrect default value

Created by: thomas-bc

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Using the Java generator, the generated Model for an Object that references another Object that has "additionalProperties" fails to compile. This is because the default value of the property is not correctly set, see in generated Bar.java:

private Foo foo = new HashMap<String, Object>();
openapi-generator version

4.3.0 Bug has already been reported for versions 4.0.0 to 4.0.3 in https://github.com/OpenAPITools/openapi-generator/issues/3456

OpenAPI declaration file content or url

https://gist.github.com/thomas-bc/549582b87073b8e02971fb623e30cabc Snippet:

definitions:
  Foo:
    type: object
    properties:
      asdf:
        type: string
    additionalProperties:
      type: object
  Bar:
    type: object
    properties:
      foo:
        $ref: '#/definitions/Foo'
Command line used for generation

$ java -jar ./openapi-generator-cli-4.3.0.jar generate -g java -i ./swagger.yaml -o ./generated_example

Steps to reproduce
  1. Download openapi-generator-cli-4.3.0.jar and swagger.yaml file
  2. Generate using command mentioned above
  3. Try compiling generated Java code with ./gradlew assemble

This will throw a compiling error:

in /generated_example/src/main/java/org/openapitools/client/model/Bar.java:35: error: cannot find symbol
  private Foo foo = new HashMap<String, Object>();
                       ^
  symbol:   class HashMap
  location: class Bar
1 error
Expected generation

private Foo foo = new Foo(); or no default value: private Foo foo;

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/3456

Assignee
Assign to
Time tracking