[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