Skip to content

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

Description

@NilsDammenhayn

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 #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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions