-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[kotlin] enforce fields in data classes #19526
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
[kotlin] enforce fields in data classes #19526
Conversation
Can anyone of you review quickly? Thanks! Note: Maybe not using class at all but just "object" would be a good idea. Your call though @dr4ke616 @stefankoppier @yutaka0m |
can you please follow step 3 to update the samples so that the CI can test/verify the change? cc @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) |
@wing328 I ran the 3 commands when I made the commit already, and had no additional changes. Reran again now, git status remains clean. Unless I should add additional things, I would say step 3 is handled. |
you're right. samples are up-to-date one thing i don't understand is how come there's no change in the samples as there are more test models with properties i'll take another look later this week and run some tests did you test the fix locally? I assume it works for your use cases |
It does work. Out of interest, what are you expecting to change? If there were a sample about empty data, someone would probably have noticed that it generates code that does not compile. (I am new to this project and do not have any profound knowledge about the CI setup etc) |
@@ -74,7 +74,7 @@ import {{packageName}}.infrastructure.ITransformForStorage | |||
@Deprecated(message = "This schema is deprecated.") | |||
{{/isDeprecated}} | |||
{{>additionalModelTypeAnnotations}} | |||
{{#nonPublicApi}}internal {{/nonPublicApi}}{{#discriminator}}interface{{/discriminator}}{{^discriminator}}data class{{/discriminator}} {{classname}}{{^discriminator}} ( | |||
{{#nonPublicApi}}internal {{/nonPublicApi}}{{#discriminator}}interface{{/discriminator}}{{^discriminator}}{{#hasVars}}data {{/hasVars}}class{{/discriminator}} {{classname}}{{^discriminator}} ( |
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.
@jaqxues the hasVars
is true when the model has at least one property.
what I don't understand is there's no change to the samples (e.g. kotlin petstore client) given that the test petstore pet has at least one model with properties.
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.
This fixes an issue with models without properties, so the opposite case. A data class
in kotlin is not allowed to have no properties. So this compilation error is fixed by not making it data class
in that special case. But I am not sure if it makes sense to change the class
to object
even in that special case.
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.
Thanks for the clarification 👍
Fix #14710
PR checklist
Commit all changed files.
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*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)