OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][resttemplate] object that consists only of additionalProperties leads to broken code generation since 7.12.0

Open
#20,795 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

After updating from 7.11.0 to 7.12.0 my code generation breaks. The given example (for me) has two issues:

  1. The generated code does not compile anymore. The hashCode-method looks like this return Objects.hash(, additionalProperties);. It does compile as soon as you add at least one parameter to the SampleClass though. Then the hashCode method is correct.
  2. The generated class does not extend HashMap<String, Object> anymore but has a parameter called "additionalProperties". I rely on the generated class being a map, which I thought is correct for a schema like that.
openapi-generator version

7.12

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: "TEST"
  version: 1.0.0
components:
  schemas:
    SampleObject:
      type: object
      additionalProperties:
        type: object
Generation Details

I'm using Java 21 and Gradle 8.13. Here is my config

{
  "dateLibrary": "java8",
  "useJakartaEe": true,
  "library": "resttemplate",
  "enumPropertyNaming": "legacy",
  "generateAliasAsModel": true
}

When registering the Gradle task I do set globalProperties.set(mapOf("models" to "")) so I only get my model file generated.

Steps to reproduce
  • Create the example.yaml above
  • Execute the code generation with the provided config
  • Compare generated classes in 7.11 and 7.12
    • 7.12 does not compile and does not extend HashMap
    • 7.11 does compile and extends HashMap
Related issues/PRs

I assume that this has to do with this PR https://github.com/OpenAPITools/openapi-generator/pull/19706 taken from the 7.12's release notes.

Suggest a fix

I'm quite sure this is not supposed to happen like that, as the code does not even compile anymore. Or am I doing something wrong here?

Thank you very much!

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 example OpenAPI declaration and the resttemplate generation configuration, then compare the generated SampleObject from versions 7.11 and 7.12. Read related PR 19706 and trace the model-generation path it changed. Done means the generated class compiles, has a valid hashCode method, and extends HashMap<String, Object> for an additionalProperties-only schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.