openapi-generator: [java] Combining "properties" and "additionalProperties" in one class generates broken Jackson mapping.
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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 27
- Comments: 23 (10 by maintainers)
Commits related to this issue
- fix: #1466 additionalProperties works now in spring generator — committed to benfonty/openapi-generator by benfonty 3 years ago
- fix: #1466 additionalProperties works now in spring generator — committed to benfonty/openapi-generator by benfonty 3 years ago
- fix: #1466 additionalProperties works now in spring generator — committed to benfonty/openapi-generator by benfonty 3 years ago
- Fix #1466 for jaxrs-cxf — committed to ABM-GmbH/openapi-generator by ssiegler 3 years ago
- fix: #1466 additionalProperties works now in spring generator — committed to benfonty/openapi-generator by benfonty 3 years ago
- chore: chore: #1466 solved rebase conflicts — committed to benfonty/openapi-generator by benfonty 3 years ago
- fix: #1466 additionalProperties works now in spring generator — committed to benfonty/openapi-generator by benfonty 3 years ago
- chore: chore: #1466 solved rebase conflicts — committed to benfonty/openapi-generator by benfonty 3 years ago
- fix: #1466 additionalProperties works now in spring generator (#11572) (fix #1466) * fix: #1466 additionalProperties works now in spring generator * chore: chore: #1466 solved rebase conflicts ... — committed to OpenAPITools/openapi-generator by jameswynn a year ago
- fix: #1466 additionalProperties works now in spring generator (#11572) (fix #1466) * fix: #1466 additionalProperties works now in spring generator * chore: chore: #1466 solved rebase conflicts ... — committed to makru86/openapi-generator by jameswynn a year ago
- fix: #1466 additionalProperties works now in spring generator (#11572) (fix #1466) * fix: #1466 additionalProperties works now in spring generator * chore: chore: #1466 solved rebase conflicts ... — committed to padteclab/openapi-generator by jameswynn a year ago
I think that having a member of HashMap instead of extending HashMap would address the issue. @JsonAnyGetter and @JsonAnySetter are designed for this exactly. Like @FatCash suggested, there could be a feature flag that would allow backward compatibility (though it seems broken right now anyway)
Any updates on this?
Any updates on this issue?
Also having problems with serialize/deserialize properly because of this. Desired approach would be to populate a mustache flag like {{hasAdditionalProperties}} on class level (not vars level), similar to {{isMapContainer}} which is currently true if
additionalProperties: trueThen we could use it however we want in mustache to add the otherProperties field and necessary json annotations and builders etc…The automatic
extends HashMap<...>should not be there, instead users can add that themselves in mustasche by checking the {{hasAdditionalProperties}} flag.We are facing the very same issue using openapi-generator-gradle-plugin : 4.0.1 and the
jaxrs-jerseygenerator.Are there any workarounds beside not using both (i.e.
propertiesandadditionalProperties) at the same time? Are there any plans to fix it?Thanks!
Hello, I created this pull request a long time ago and did not receive any approval at the time. If anybody wants to take it over, feel free.
Hi, this issue is blocking my team as well. @Zomzog , @banlevente , @borsch , @javisst , @cachescrubber , @welshm , @MelleD, @atextor, @manedev79, What is the status on this issue? I tried to contact @jameswynn with no success. I’m happy trying to merge this pull request if need be.
curious if this was ever fixed?