-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[kotlin] [client] Implement inheritance and oneOf support in kotlin-client #12924
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
Conversation
...tore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/models/BirdAllOf.kt
Outdated
Show resolved
Hide resolved
.../petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/models/Bird.kt
Outdated
Show resolved
Hide resolved
4c953b7
to
1d6818e
Compare
Hey @vlsergey first of all, thanks for taking the time to create this PR.
Thanks |
Hi @4brunu. I did clean / package / generate-samples multiple times (all samples, not only kotlin ones), but locally i have no new/changes files. I have no idea why CI reports changes in swift examples. Neverless i've updates own branch with latest master and tried to push again. |
...penapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
Outdated
Show resolved
Hide resolved
This PR touches in a lot of places that I don't have a lot of knowable and it quick extensive, so I have a hard time reviewing it. |
cc @OpenAPITools/generator-core-team can someone please help to review this PR, because it touches in parts that I don't know? Thanks |
Any updates on this? It would be really useful. |
Will this interfere with #12966 ? |
When using this with in kotlin multiplatform, i noticed the generated "AnyOf" classes attached a @Serializable
interface PaginatedAwardAllOf {
@SerialName(value = "data") val `data`: kotlin.collections.List<Award>?
} |
Is this PR still alive? What needs to be done to get it merged? |
I'm actually not sure if this PR works as expected. The initial schema is (excerpt):
So The models created for that are
Which reads to me as: Shouldn't this rather be something like
(or possibly even a sealed class/interface |
Interesting, i will look into it. May be there is a mismatch between allOf and oneOf logic, that need to be handled. |
7e9c626
to
18f6c4c
Compare
WIP: data class Foo /* ... */ : Entity
data class Bar /* ... */ : Entity
interface FooRefOrValue Now looking how to make Bar and BarRef implements BarRefOrValue interface |
Done: data class Foo /* ... */ : Entity, FooRefOrValue
data class Bar /* ... */ : Entity, BarRefOrValue
interface FooRefOrValue Change note: i've removed inherited variables processing from |
718d48e
to
2788283
Compare
|
a9065a3
to
24c2a3c
Compare
Sorry, I have been busy in the past days. I had a look into the generated Kotlin models and they definitely look better than at the time of my previous comment. So far I would say that everything seems to be as expected, good work! Unfortunately, we have moved away from inheritance due to other issues (unrelated to the generator) so I don't have a real use case anymore and won't be able to do thorough testing. I'm wondering why a Kotlin implementation changes lines in Java models, though, but did not look into that further. Possibly this will be resolved by a rebase. |
19023a2
to
0115d78
Compare
thanks for the PR. looks like a major change so i'll test it out later and target v7.0.0 release. |
Great work! I've used your PR to implement oneOf for kotlin-spring generator, it works great! Looking forward this to be merged so I can push my own PR :) |
We see this pr did not make it to 7.0.0-beta release. Are you still planning to add it to 7.0.0 release? |
I tried copying the mustache templates over and using them myself. Unfortunately this doesn't compile for me when I remove the Furthermore, I didn't see any hierarchy in the classes generated that used the |
@@ -2623,7 +2623,7 @@ protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<S | |||
|
|||
// TODO revise the logic below to set discriminator, xml attributes | |||
if (supportsInheritance || supportsMixins) { | |||
m.allVars = new ArrayList<>(); | |||
m.allVars = m.allVars == null ? new ArrayList<>() : m.allVars; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please explain this change?
looks like this change impacts the spring codegen as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please explain this change?
It was obvious mistake to assume that allVars is null and need to assigned to ArrayList. Well, it was null in most cases, but in some rare ones it's already populated with important data and shall not be cleared by re-instantiation.
looks like this change impacts the spring codegen as well.
yes, it may. But I've checked, didn't look like a problem year ago.
@thejeff77 I don't think oneOf should result any hierarchy in the classes generated. |
Please try the For the implementation in this PR using interface, I don't think it can handle the following:
|
@vfouqueron can you please publish your work? BTW. I have updated the original patch to the v7.x state, though pretty "mechanically", without deep understanding how things have changed since v6.x. |
Also I have discovered the the original patch incorrectly handles the "Fruit/Apple/Banana" testcase from v7.x and master. The generated code is:
and, obviously, it can't be compiled due to:
@vlsergey, can you take a look at this? I'd suppose the generated |
@amorozov Sorry for the late reply, it's available on my repo and on that branch https://github.com/vfouqueron/openapi-generator/tree/release/vf-7.0.x I've done a bunch of other improvements that I need to push back here. It solved all my issues, but some are really impacting and I have no idea if I've broken something else in another generator. I should take time to push everything back here. |
Finishing this would be very much welcome! What's the reason behind closing this PR, please? |
Add example based on
oneof_polymorphism_and_inheritance.yaml
schema and fix all problems that prevented to correctly implement it:override
flags so kotlin code can be compiled nowAddinheritedVars
collection toCodegenModel
thus we can correctly handle case when property specified both in current and parent modelI do believe that it is a non-breaking change for compilable code generation, but it surely will change how non-compilable kotlin code generated (and makes it compilable)
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.1.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)@jimschubert, @dr4ke616, @karismann, @Zomzog, @andrewemery, @4brunu, @yutaka0m