-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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] Java generation of 'extra' class with allOf #3100
Comments
And it's not about presence of extra class only. The expected inheritance is missing as well. |
I'm facing this issue as well. But when I have realized the version 4 of generator working this way I asked myself if this was intended or really a weird bug. Could someone clarify it? I was pretty happy with 3.3.4 so I will go back to it for now. I rely on Java inheritance. |
Also happen in csharp client and server #3338 |
That's treated as an inline schema (which can be replaced with $ref to avoid the additional model generation). If users prefer the old way of not generating this inline schema, technically we can add an option to restore the old behaviour. |
The proposed solutions would lead to a file being generated for the inline schema again. That sounds a bit counter-intuitive. Why would I want to give the inline schema a dedicated name, if I didn't had the need before? |
@wing328 any comment on my post above? Is it possible to add the option to add the old behaviour? |
This seems to miss the point entirely. Spec authors understand that these are inline schemas and are used precisely "to avoid the additional model generation". Replacing with a
It seems clear from the number of bugs raised in this area that many users do "prefer the old way". What I'm really not clear on is:
|
Still got this problem on 4.2.2. |
This is also a behavior for .net generators. Still an issue in 4.3.0 |
Even the examples have this issue. For example, the Java RestEasy example has several files with These files are not used at all by the API. The only reference to this class is an unused import from |
What about using |
@wing328 That seems like a strange solution to me. Why would I need to ignore files that shouldn't have been generated in the first place? Also, as I said, the classes are referenced by an unused import from other classes. Deleting the files, breaks the build. |
Great! Using .openapi-generator-ignore including "**/*AllOf.cs" for .net generation solves this. |
Understood that not all users want these allOf classes. The original PR is try to make the behavior consistent (generating a model for inline schema) but clearly not everyone likes it. I'll think about this more and see what I can do, probably in the upcoming 5.0.x release in May/Jun in which breaking changes are expected. |
Good news to listen about restoring to the original behavior. We rely upon inheritance that the |
That's not going to be restored. You will need to use |
Facing the same issue here, where configuring the generator to ignore these AllOf files causes the classes to not compile due to these AllOf classes being imported (even though they're unused). Using Java here. |
Can someone explain why these |
(Sorry for the bit delay...) Sure @wing328 we use the Aside of that, and as others state, the new generated classes Is there any news for the |
I've just realized that I have been confused on all my previous assertions regarding inheritance. The inheritance is not actually broken and seems never was (I've tried again with several generator versions 4.0, 4.02, 4.0.3, 4.1, 4.3.1) and Java inheritance is still fine. So I apologize if I introduced noise. I think other commenter stated the inheritance was broken as well. So the actual problem is only about the extra unuseful The main point is that this pollutes the generated JAR with unnecessary, unused classes, so breaks the point of a sane API artifact. I've just tried using the Maybe I could hack the POM of my generator (here using |
That seems like the most solvable problem -- if the generated file only imported classes it used, then the .openapi-generator-ignore trick would work. |
As a workaround I can suggest adding
That works because composed schema (allOf, oneOf, anyOf) that also defines |
Are there any news about this? Is it on the roadmap for the upcoming 5.x release? |
When you change from:
To:
So, if additional properties for |
Very nice Workaround @milczarekIT Does anyone know if this behavior is intended? I could not find any documentation for this. |
@milczarekIT Nice workaround. It allowed me to generate the intended client code without the dummy classes (I'm using csharp-netcore 5.0.0-SNAPSHOT). Does anyone know if this is still valid OpenAPI syntax though? I haven't found any official examples with this structure. |
That is a nice workaround. Sadly for Java the "builder" methods does not work since they return the super type, e.g.
I've tried so many different patterns but none of them work for Java inheritance, this was the closest though, but I can't live with:
nor...
nor...
A simple override of the builder methods would suffice I believe, e.g.
Then this workaround would be very acceptable imo. |
There's the same problem with kotlin and kotlin-server (in 5.0.1) |
@wing328 why can't you just have the old behavior? I think a lot of folks are disappointed with the new behavior. We are supposed to make things better not worse. Thanks! |
Since I annotate the @Schema directly in my java code and even generate openapi.yml out of it, I cannot influence the positioning of :allOf ref much (as in the nice hack above ;-)
To OpenApi developers:
Thanks for fixing soon and appreciate your work! I am not sure if I understood the inheritance spec well, but my Java implementation looks as follows:
Besides I am using:
|
I am not sure what the status is of this. I have specified
OrganizationPage must be an instance of BasePage but it is not. instead all the properties from BasePage are included in OrganizationPage. If this syntax no longer causes inheritance what is the new spec format that does? |
@rgoers the corrent form should be something like this #3100 (comment) |
I tried
and
they both ended up with
instead of
which is what I really need. However, the format that has everything under the allof element also generates a class named OrganizationPageAllOf as
but this class has none of the attributes from BasePage and doesn't extend it so it is unusable for anything. So what do I need to do to get OrganizationPage to extend BasePage? |
Still seeing this as an issue. Interestingly the swagger-codegen doesn't produce these extra files. |
It's been 3 years, this issue is still open. the swagger-codegen doesn't produce this extra files. But why openapi-generator still produce this extra files? Could you please give us explanation / insight wether these extra files useful or no @wing328 ? |
I've filed #13498 to improve how the allOf inline schemas are created. Please give it a try as follows:
(if you're using mvn wrapper that comes with the project, just replace I tested with java, csharp-netcore and the result is good - no longer seeing those *AllOf files created. |
Tagging @msymonov @gerardbosch @yilinjuang @valliman @roxspring @nexen505 @ahokkonen @papegaaij @sko-ob @jharmelink @gmcelhoe @surmabck @gerlacdt @milczarekIT @MattLichter @thobiaskarlsson @stapel @mizolight @phirzel @rgoers @ntroutman @efriandika to review the PR 🙏 Have a nice weekend. |
Is there any hope of getting the fix into the main release any time soon? This parser is unusable for any openapi document that uses "allOf". |
Guys, I'd be happy to help if there's any way I can, but this is a huge blocker for me. Any hope of getting a fix soon? |
The problem still occurs in the plugin. When merging together 2 YAML files, one of which has an allOf object, the resulting YAML file still has the 3 objects (Object1, Object2, Object2_allOf) |
Closed via #15682 Please pull the latest master to give it a try. |
(sorry for my testing delay, after SpringBoot v3.0.6 migration and upgrade of openapi-generator-maven-plugin to v6.5.0 I do not see those unnecessary *AllOf imports in the generated ApiClient code any more - we use Java and @Schema annotation in code as illustrated above in my ancient post). Whoever solved the issue, THANKS a lot!) |
@phirzel no need to sorry. Glad that you no longer encounter the issue. |
@wing328 Hi William. Currently using v7.0. I have a field with type "Object" and this field is generated as a new class "...AllOfType". I want it to stay as Object, and do not want the new AllOfType class. Anything I can do? |
Description
I am using the pet store example to create java classes with inheritance. In the newest release (4.0.1) I found a bug. When I generate code with the OpenApi declaration file it generates an extra class.
The class 'CatAllOf' I did not expect. It looks the same as 'Cat' except that it does not extends Pet.
OpenAPI declaration file:
openapi-generator version
I used the gradle plugin with version 4.0.1.
older version
I tested the same thing in the version 4.0.0-beta3 and there I did net see the 'extra' class. In other words, I got the expected behavior. It seems the bug was introduced with the latest release.
The text was updated successfully, but these errors were encountered: