OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Referencing Object with additionalPorperties does not import HashMap in Model

Open
#3,456 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Generating Model for a Object that references an object that has "additionalProperties" fails to generate the import for HashMap

openapi-generator version

affected Version(s): 4.0.0 to 4.0.3
Not affected: 3.3.4 (sets the field to null, so no import is needed here)

OpenAPI declaration file content or url

Snipped:

    WithAdditinalPropertiesDTO:
      type: object
      properties:
        id:
          type: string
      additionalProperties: {}

    BrokenDTO:
      type: object
      properties:
        id:
          type: string
        withAdditinalProperties:
          $ref: '#/components/schemas/WithAdditinalPropertiesDTO'

gist: https://gist.github.com/FloKaemmerer/54a9663183688b0d5658a8064c32f695

Command line used for generation

mvn clean compile

used pom: https://gist.github.com/FloKaemmerer/9789a0fc5bfca47b6c4cf50c7573434b

Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OpenAPI YAML snippet and the provided pom, then run mvn clean compile to reproduce the generated Java model problem. Inspect the generated BrokenDTO and its imports, using the gist examples as reference. Done when the generated model imports HashMap for the referenced additionalProperties object and compilation succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.