-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] [JAVA] combining properties and additionalProperties generates broken Model class #17361
Comments
Thank you for pointing out that the bug had already been fixed in the Spring generator. This enabled me to create a simple workaround consisting of two steps:
Ugly, but it happened to work. |
It seems worse for me - even setting We explicitly set this property to false to make sure our validation correctly fails if our examples have unknown types, as the default of openapi 3.1 is to allow additional properties. Example:
Result: /**
* ReproductionDemoNested
*/
@JsonPropertyOrder({
ReproductionDemoNested.JSON_PROPERTY_TEXT_FIELD
})
@JsonTypeName("DemoNested")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-09-23T11:41:21.482102+02:00[Europe/Amsterdam]", comments = "Generator version: 7.8.0")
public class ReproductionDemoNested {
public static final String JSON_PROPERTY_TEXT_FIELD = "textField";
private String textField; versus: schemas:
DemoNested:
type: object
additionalProperties: false
required:
- textField
properties:
textField:
type: string resulting in /**
* ReproductionDemoNested
*/
@JsonPropertyOrder({
ReproductionDemoNested.JSON_PROPERTY_TEXT_FIELD
})
@JsonTypeName("DemoNested")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-09-23T11:41:09.715975+02:00[Europe/Amsterdam]", comments = "Generator version: 7.8.0")
public class ReproductionDemoNested extends HashMap<String, Object> {
public static final String JSON_PROPERTY_TEXT_FIELD = "textField";
private String textField; |
Hey! I'm facing the same issue with the |
I've created the pull request #19706 to fix the issue for the |
Awesome. We use the feign library - I haven't checked it in enough detail yet, but how hard would it be to port your fix to that library as well? Edit: I see you mention this should already work with feign? That's odd since we do see an issue still. |
Sounds great! We use the webclient library.
|
Hey @lesteenman! I've created the pull request #19713 to fix the same issue for the I was not able to reproduce the issue with |
Bug Report Checklist
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
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
.The text was updated successfully, but these errors were encountered: