Skip to content

feat(plugin): Support mapping kotlin properties names to camelCase in generated code#426

Merged
Chuckame merged 45 commits intoavro-kotlin:mainfrom
Lee-WonJun:feature/field-nameing-plugin
Jan 19, 2026
Merged

feat(plugin): Support mapping kotlin properties names to camelCase in generated code#426
Chuckame merged 45 commits intoavro-kotlin:mainfrom
Lee-WonJun:feature/field-nameing-plugin

Conversation

@Lee-WonJun
Copy link
Copy Markdown
Contributor

@Lee-WonJun Lee-WonJun commented Dec 13, 2025

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 NameStrategy interface for code generation

    • Built-in strategies: IDENTITY, CAMEL_CASE
    • Support for custom strategies
  • Since 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 KotlinGenerator to apply the configured naming strategy

  • Default behavior remains unchanged (IDENTITY)

Note

Although an existing FieldNamingStrategy exists, 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 FieldNamingStrategy tailored specifically for this use case.

Related Issue

Closes #425

@Lee-WonJun
Copy link
Copy Markdown
Contributor Author

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.

@Chuckame
Copy link
Copy Markdown
Member

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 👌

@Lee-WonJun Lee-WonJun force-pushed the feature/field-nameing-plugin branch from a3bcc4d to 1e067ec Compare January 10, 2026 12:32
@Lee-WonJun Lee-WonJun marked this pull request as draft January 10, 2026 12:38
@Lee-WonJun Lee-WonJun marked this pull request as ready for review January 10, 2026 14:18
@Lee-WonJun Lee-WonJun requested a review from Chuckame January 10, 2026 14:23
@Lee-WonJun Lee-WonJun marked this pull request as draft January 14, 2026 13:32
@Lee-WonJun Lee-WonJun force-pushed the feature/field-nameing-plugin branch from 4fb8218 to 435e4cb Compare January 14, 2026 15:18
@Chuckame
Copy link
Copy Markdown
Member

Just for you to know, I've merged many PRs.

Basically, the main changes for you are:

  • Avro4kPluginSourcesGenerationExtension has been moved to its own file
  • you can add schemas with -fail at the end to test failing scenarios in kotlin-generator

@Lee-WonJun Lee-WonJun force-pushed the feature/field-nameing-plugin branch from d45cf17 to 010f712 Compare January 18, 2026 04:26
@Lee-WonJun Lee-WonJun force-pushed the feature/field-nameing-plugin branch from b12a11b to f1e27ec Compare January 18, 2026 06:13
Copy link
Copy Markdown
Member

@Chuckame Chuckame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the last pass, for improving a bit the docs after the rebase. Then we can merge !!!

@Lee-WonJun
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

@Chuckame Chuckame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the PR! Don't hesitate if you want to contribute more on other aspects!

@Chuckame Chuckame merged commit 1d420fc into avro-kotlin:main Jan 19, 2026
1 check passed
@Lee-WonJun
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I really enjoyed working on this PR—it was a great experience

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Field Naming Strategy Support to Gradle Plugin

2 participants