feat(plugin): Support mapping kotlin properties names to camelCase in generated code#426
Conversation
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/NameStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/NameStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/KotlinGenerator.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/KotlinGenerator.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/KotlinGenerator.kt
Outdated
Show resolved
Hide resolved
...ted-sources/field_naming_pascal/com/github/avrokotlin/avro4k/fieldnaming/PascalCaseRecord.kt
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/kotlin/com/github/avrokotlin/avro4k/plugin/gradle/Avro4kGradlePlugin.kt
Outdated
Show resolved
Hide resolved
|
Thanks for the detailed review. I generally prefer leaving customization points open (especially for libraries), so I initially planned to add a custom option and did think about Gradle configuration/cache implications. That said, I agree that exposing this level of flexibility in the Gradle DSL may not be worth the added complexity, and it could also be a maintenance burden. I’ll align with your philosophy as the maintainer and revise the implementation based on your feedback. For context, as mentioned in the original issue, I’m currently using this only via the Gradle plugin path, so my perspective may not fully match the project-wide point of view. Your review was helpful in that regard as well. |
|
At the beginning of my contribution on avro4k, I've been opening a lot the customisation. But this became much more complex to maintain, as any new feature can quickly be against previously open customization. Now I'm more YAGNI : You Ain't Gona Need It, until I or someone really needs it. Lets continue the discussion on your actual need in the issue 👌 |
a3bcc4d to
1e067ec
Compare
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/KotlinGenerator.kt
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/KotlinGenerator.kt
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
…nSourcesGenerationExtension
…ter camelCase handling
…mprove naming consistency
…roved camelCase handling
4fb8218 to
435e4cb
Compare
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/kotlin/com/github/avrokotlin/avro4k/plugin/gradle/Avro4kGradlePlugin.kt
Outdated
Show resolved
Hide resolved
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/FieldNamingStrategy.kt
Show resolved
Hide resolved
|
Just for you to know, I've merged many PRs. Basically, the main changes for you are:
|
d45cf17 to
010f712
Compare
b12a11b to
f1e27ec
Compare
kotlin-generator/src/main/kotlin/com/github/avrokotlin/avro4k/KotlinGenerator.kt
Show resolved
Hide resolved
Chuckame
left a comment
There was a problem hiding this comment.
I did the last pass, for improving a bit the docs after the rebase. Then we can merge !!!
Co-authored-by: Chuckame <[email protected]>
Co-authored-by: Chuckame <[email protected]>
Co-authored-by: Chuckame <[email protected]>
Co-authored-by: Chuckame <[email protected]>
|
LOL — I didn’t realize “Add suggestion to batch” was for committing them all at once. I thought it was something like CI-related, so I applied each suggestion individually. Turns out I could’ve done it in one go. |
Chuckame
left a comment
There was a problem hiding this comment.
Many thanks for the PR! Don't hesitate if you want to contribute more on other aspects!
|
Thanks for the feedback! I really enjoyed working on this PR—it was a great experience |
Summary
This PR adds useKotlinConventionForFieldNames to the Avro4k Gradle plugin for mapping avro record names compliant with the kotlin standards.
Previously, Avro schema field names were used verbatim when generating Kotlin property names.
With this change, users can transform field names during code generation to better align with Kotlin naming conventions.
Changes
Introduced a new
NameStrategyinterface for code generationIDENTITY,CAMEL_CASESince Gradle cannot detect changes in custom strategies,
a name strategy identifier was added to force invalidation of the incremental build cache (I couldn’t find a better approach for handling interface-based configuration in the plugin)
Updated
KotlinGeneratorto apply the configured naming strategyDefault behavior remains unchanged (
IDENTITY)Note
Although an existing
FieldNamingStrategyexists, it does not appear to be intended for Avro → Kotlin code generation.Because code generation has different requirements, this PR introduces a simpler and more deterministic
FieldNamingStrategytailored specifically for this use case.Related Issue
Closes #425