dgs-codegen icon indicating copy to clipboard operation
dgs-codegen copied to clipboard

feature: add support for object input default values and add support for default inputs to kotlin2

Open dwilkolek opened this issue 1 year ago • 4 comments

Fixes default object values for input parameters when using Kotlin codegen

closes #297

dwilkolek avatar Apr 21 '24 13:04 dwilkolek

Sure, I'll take a stab at it shortly.

dwilkolek avatar Apr 21 '24 22:04 dwilkolek

While peeking at java code path I've found a bug in kotlin path. When using typeMapping with Person to DifferentlyNamedClass mapping then it would fail.

Regarding Java path it will be slightly more difficult. In Kotlin path I used named parameters. In Java I see 4 paths:

  1. create json object and use ObjectMapper to create object in place
  2. use default no param constructor and call setters in initialiser block
  3. use constructor with arguments but it will require the same order and matching constructor for mapped types
  4. use builder - this would be great for generated classes, but will most likely fail for type mapped classes.

dwilkolek avatar Apr 22 '24 07:04 dwilkolek

I've implemented option 2. Lmk what do you think 🙏

dwilkolek avatar Apr 22 '24 16:04 dwilkolek

I realised that kotlin2 did not support default values at all. Now experience with default values should be the same across codegen configurations.

dwilkolek avatar May 02 '24 11:05 dwilkolek

@mbossenbroek This PR contains kotlin2 changes - added support for default values in input types 😉 @srinivasankavitha I've implemented java code path using initialiser block

If it make sense to you I can split changes into 2 PRs; one for object defaults, one adding kotlin2 default values

dwilkolek avatar May 14 '24 17:05 dwilkolek

Looks good to me! 👍 I'll let @srinivasankavitha merge it cause there are other changes in there too

mbossenbroek avatar May 14 '24 19:05 mbossenbroek

@srinivasankavitha Are you waiting for any action from my side or is it ready to go? I'm not a huge fan of stale PRs hanging out in void 😅

dwilkolek avatar Jun 24 '24 20:06 dwilkolek

Sorry for the delay, and thanks for bringing this back to my attention. Just merged the PR and will go out in next week's release.

srinivasankavitha avatar Jun 24 '24 21:06 srinivasankavitha