-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix ConfigProvider's kebabCase and snakeCase to handle numeric boundaries #9921
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
Fix ConfigProvider's kebabCase and snakeCase to handle numeric boundaries #9921
Conversation
eb1ce0e to
94ad413
Compare
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.
Pull Request Overview
This pull request fixes the ConfigProvider's kebabCase and snakeCase methods to correctly insert separators between letters and numbers, aligning the behavior with zio-config.
- Improved handling for letter-to-number and number-to-letter transitions
- Additional regex replacement steps to handle consecutive uppercase letters
- Updates to tests to cover new edge cases in both kebabCase and snakeCase
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/shared/src/main/scala/zio/ConfigProvider.scala | Updated kebabCase and snakeCase functions with refined regex replacements |
| core-tests/shared/src/test/scala/zio/ConfigProviderSpec.scala | Added tests to cover cases with numeric boundaries, acronyms, and mixed cases |
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.
I'm not against fixing this, but I'm abit reserved to approve it without having some sort of fallback for users that will be affected by this change.
Depending on the setup, updating config keys can be quite painful (to say the least). e.g., in cases that the config file is saved somewhere remotely (e.g., S3) and added to the container during runtime, it'll be difficult to coordinate the update of the config with the service update.
Would it be possible to add a deprecated method so that users can switch to the old behaviour if needed? We could either name it something like snakeCaseLegacy or overload the snakeCase method to accept a legacy: Boolean argument. Or something along these lines I don't mind either way as long as users have the option to use the old behaviour
3009bb2 to
1a50aad
Compare
kyri-petrou
left a comment
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!
This PR fixes
ConfigProvider.kebabCaseandConfigProvider.snakeCaseto properly handle transitions between letters and numbers, aligning with the standard implementation used in zio-config.The Issue
The current regex-based implementation only handles [a-z][A-Z] transitions:
userID2FA→user-id2fa(missing:user-id-2-fa)version2API→version2api(missing:version-2-api)The Fix
Added proper handling for:
version2→version-22FA→2-faHTMLParser→html-parserThis brings consistency with https://github.com/zio/zio-config/blob/d0682b52ec39440fa04b2192df9d0c1ab269a39b/core/shared/src/main/scala/zio/config/KeyConversionFunctions.scala#L38.
Breaking Change Notice
some-key23valueforsomeKey23Value) will need to update tosome-key-23-value. So yeah, no pressure to merge.