-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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] No more inheritance for components generated by version 5.0.0 #8495
Comments
Just to confirm. I updated from 4.3.1 -> 5.0.0 and I'm seeing the same issue (with dotnet-core generator) and AllOf inheritance. If any help, here is a git diff of 4.3.1 generated class and 5.0.0 generated class which shows the issue:
namespace FOOBAR.Model
{
@@ -29,7 +29,7 @@ namespace FOOBAR.Model
/// ProductBankLoan
/// </summary>
[DataContract(Name = "ProductBankLoan")]
- public partial class ProductBankLoan : Product, IEquatable<ProductBankLoan>
+ public partial class ProductBankLoan : IEquatable<ProductBankLoan>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="ProductBankLoan" /> class.
@@ -38,9 +38,12 @@ namespace FOOBAR.Model
/// <param name="productID">productID.</param>
/// <param name="debtors">debtors.</param>
/// <param name="collaterals">collaterals.</param>
- public ProductBankLoan(double balance = default(double), int productID = default(int), List<Debtor> debtors = default(List<Debtor>), List<Collateral> collaterals = default(List<Collateral>)) : base(productID, debtors, collaterals)
+ public ProductBankLoan(double balance = default(double), int productID = default(int), List<Debtor> debtors = default(List<Debtor>), List<Collateral> collaterals = default(List<Collateral>))
{
this.Balance = balance;
+ this.ProductID = productID;
+ this.Debtors = debtors;
+ this.Collaterals = collaterals;
} |
I am going to revert to 4.3.1. :( |
@antonio-petricca I'm getting this from the log when running the generator: [main] INFO o.o.codegen.utils.ModelUtils - [deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated in the 5.x release. Composed schema name: null. Title: null
[main] INFO o.o.codegen.utils.ModelUtils - [deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated in the 5.x release. Composed schema name: null. Title: null I havn't had time to dive into it fully yet (we've reverted to 4.3.1 for now) but from what I can gather it seems that my swagger.json doesnt have the discriminator field on the supertype. However I'm using asp.net swashbuckle to generate the swagger.json/.yaml which is setup to OAS3. So what I havn't figured out yet is if the problem really is the yaml not being generated correctly by swashbuckle (i.e. missing the discriminator field). I cant seem to get it to generate the discriminator field. (yet - working on it when I have time) |
This happened to me after upgrading from UPDATE: |
I have the same problem from 5.x.x. Actually, the following warning doesn't make sense :
As I have a propertyName placed on the discriminator on the parent object :
Are there any update on this that could avoid rollbacking to 4.3.1? |
I reverted to 4.3.1. |
I have the same problems with kotlin-spring generator. |
This might be a bug in how ambiguousness of inheritance is being determined. I'm on it |
I don't know if it's related to this bug, but I documented what worked for me here: |
So right now the issue is the following: The spec itself says that allOf by itself does not imply a hierarchic relationship between the components. Therefore even if there is only a single reference in allOf this means that generating an inheritance relationship between them is not per se wrong (as the spec does not forbid it) but it also goes further than the spec and infers something that some people might not want to have. I've opened an issue on the OpenAPI Spec itself to maybe get some clarification into the spec as to whether treating a single allOf ref as inheritance might make sense. For now the solution is to simply add a discriminator property to the base object in order to get inheritance. |
@Blackclaws You can see a code example in my post above, and a snippet of the generated spec is shown below. Perhaps this is the wrong place for this question (but you mentioned discriminators), but am I doing something wrong here?
This is using the configuraton:
|
You need to actually add a discriminator to your base class and then add the annotation [SwaggerDiscriminator("discriminatorPropertyName")] as well. That has worked for me. |
I should do the same. |
The problem is that the behavior of adding inheritance to schema composition by allOf without a discriminator was actually non-compliant regarding the spec. If you add a discriminator everything should work as expected. See also the linked issue in the spec repository. If you want this sort of behavior then please go ahead an lobby for general code generation hints as part of the spec. |
We hit the same issue with model composition as described here: https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/ |
The problem is that the base class can't always know all the classes that will extend it. In my case, #9756 it isn't even necessary as the base class isn't used for Serialization/Deserialization. But I need the base class for methods that operate on the fields it provides. In my environment we have a "BasePage" object for paged requests. All the services that need paging extend that. BasePage can't possibly know all the services that will support paging as it is in a common library that the services import. This change has made it impossible to support this. |
Hi all, I've filed #14172 to allow using $ref as parent in allOf with a new option called "openapi-normalizer". Please give it a try as follows:
|
Hi @wing328, we tried it out with your suggestion, however didn't worked. This is the command I'm using: When executing the same command but without --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true works fine. I'm using windws 10 with JDK 19 x64 and maven 3.8.7. Thank in advance for you help. |
can you share the spec to repeat the issue? hard to troubleshoot without the spec. |
closing this as #14172 has been merged. please use https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#openapi-normalizer moving forward. |
@endreszilagyi1 I've merged #15224 with better null check. Hopefully that should address the issue you reported. |
Description
No schema inheritance.
openapi-generator version
5.0.0
OpenAPI declaration file content or url
Generation Details
The above YAML produces:
Instead as for the 4.3.1:
Suggest a fix
Does exist a configuration parameter to enforce the DTO inheritance generation? Or it is a bug?
The text was updated successfully, but these errors were encountered: