You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently upgrading from OpenAPI Generator v5.4.0 to v6.6.0 and I've run into an issue with schemas that define multiple levels of inheritance using two separate discriminators. It seems that for models that have more than one level of inheritance depth the generated Java classes are a bit broken. There are two issues that I have encountered:
Child classes don't have all required parameters needed to pass to the parents in the constructor which results in compilation errors.
Grandparent class has too many mappings using @JsonSubTypes. It seems that JsonSubTypes are generated for all classes that inherit from the grandparent class instead only for the explicitly configured classes using the mapping property in the discriminator. I would expect only the first two mappings to appear (CAT and DOG). Parent classes have their @JsonSubTypes set properly.
@JsonIgnoreProperties(
value = "type", // ignore manually set type, it will be automatically generated by Jackson during serializationallowSetters = true// allows the type to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Cat.class, name = "CAT"),
@JsonSubTypes.Type(value = Dog.class, name = "DOG"),
@JsonSubTypes.Type(value = Labrador.class, name = "Labrador"),
@JsonSubTypes.Type(value = MaineCoon.class, name = "MaineCoon"),
@JsonSubTypes.Type(value = Persian.class, name = "Persian"),
@JsonSubTypes.Type(value = Poodle.class, name = "Poodle")
})
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-06-09T14:33:49.208185800+02:00[Europe/Warsaw]")
publicclassPet {
privateStringname;
privateStringtype;
/** * Default constructor * @deprecated Use {@link Pet#Pet(String)} */@DeprecatedpublicPet() {
super();
}
/** * Constructor with only required parameters */publicPet(Stringtype) {
this.type = type;
}
}
Using v5.4.0 JsonSubTypes are properly set
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Cat.class, name = "CAT"),
@JsonSubTypes.Type(value = Dog.class, name = "DOG"),
})
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-06-09T14:40:51.917945+02:00[Europe/Warsaw]")
publicclassPet {
@JsonProperty("name")
privateStringname;
@JsonProperty("type")
privateStringtype;
}
I'm able to circumvent the first issue using --additional-properties=generatedConstructorWithRequiredArgs=false as a workaround although it would be nice to have all the constructors. Second one is something that I could not work out.
openapi-generator version
I'm using version 6.6.0, previously I've used 5.4.0 and this structure worked as expected.
* fix#16797 and #15796 spring child constructor missing parent params
* root cause and update the DefaultCodegen.java to add missing property when with multi inheritance
* rollback SpringCodegen.java
* update samples
* rollback with master cause #16992 fixed this issue too
* still using orignal design
* catchup master
* catchup master
* catchup master
* fix
* add tests
---------
Co-authored-by: dabdirb <[email protected]>
Bug Report Checklist
Description
Hello everyone,
I'm currently upgrading from OpenAPI Generator v5.4.0 to v6.6.0 and I've run into an issue with schemas that define multiple levels of inheritance using two separate discriminators. It seems that for models that have more than one level of inheritance depth the generated Java classes are a bit broken. There are two issues that I have encountered:
mapping
property in thediscriminator
. I would expect only the first two mappings to appear (CAT
andDOG
). Parent classes have their @JsonSubTypes set properly.Using v5.4.0 JsonSubTypes are properly set
I'm able to circumvent the first issue using
--additional-properties=generatedConstructorWithRequiredArgs=false
as a workaround although it would be nice to have all the constructors. Second one is something that I could not work out.openapi-generator version
I'm using version 6.6.0, previously I've used 5.4.0 and this structure worked as expected.
OpenAPI declaration file content or url
Yaml
Generation Details
Generated using openapi generator gradle plugin
Steps to reproduce
Related issues/PRs
#15148
Suggest a fix
The text was updated successfully, but these errors were encountered: