Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1466
Closed
Open
Issue created Nov 16, 2018 by Administrator@rootContributor

[java] Combining "properties" and "additionalProperties" in one class generates broken Jackson mapping.

Created by: r-alukhanov

Description

If using both "properties" and "additionalProperties", the generated class extends HashMap and contains plain properties. Like this:

public class Example extends HashMap<...>  {
  @JsonProperty("a")
  private String a;
  ...
}

Such a class cannot be meaningfully deserialised using Jackson. Jackson puts all the fields as key/value pairs into the HashMap ignoring the plain fields. In provided example getA() would return "null", while get("a") contains the value.

openapi-generator version

Used version: openapi-generator-maven-plugin : 3.3.3

OpenAPI declaration file
Example:
  type: object
  properties:
    a:
    type: string
  additionalProperties: true
Suggest a fix/enhancement

I would suggest to generate such a class (which has both "properties" and "additionalProperites") as:

public class Example {
  private String a;
  private HashMap<> otherProperties;
  ...
}

Similar suggestion in "swagger-codegen" project: https://github.com/swagger-api/swagger-codegen/issues/5187

Assignee
Assign to
Time tracking