OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] Referencing Object with additionalPorperties does not import HashMap in Model
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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