Skip to content

[BUG] [JAVA] combining properties and additionalProperties generates broken Model classΒ #17361

@Mettbrot

Description

@Mettbrot

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?
Description

Combining required properties with additionalProperties: true generates a Model class that extends HashMap. On deserialization, the given Properties are not filled, instead all properties (required and additional) are part of the Hashmap. According to FasterXML/jackson-databind#3173 this is expected behavior for Jackson so the generated Model is wrong.
This was fixed for the spring generator in #11572 but its still happening in the java generator.

openapi-generator version

7.1.0

OpenAPI declaration file content or url
    additionalPropertiesWithRequiredData:
      type: object
      additionalProperties: true
      properties:
        propA:
          type: integer
          format: int64
        propB:
          type: string
      required:
        - propA
        - propB
Related issues/PRs

#1466
#11572

Suggest a fix

The model generation should not extend HashMap, instead put additionalProperties as a HashMap inside the class and annotate it with @JsonAnySetter / @JsonAnyGetter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions