Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kitlangton
Copy link
Member

This PR fixes ConfigProvider.kebabCase and ConfigProvider.snakeCase to 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:

  • userID2FAuser-id2fa (missing: user-id-2-fa)
  • version2APIversion2api (missing: version-2-api)

The Fix

Added proper handling for:

  • Letter-to-number transitions: version2version-2
  • Number-to-letter transitions: 2FA2-fa
  • Consecutive uppercase handling: HTMLParserhtml-parser

This brings consistency with https://github.com/zio/zio-config/blob/d0682b52ec39440fa04b2192df9d0c1ab269a39b/core/shared/src/main/scala/zio/config/KeyConversionFunctions.scala#L38.

Breaking Change Notice

⚠️ While technically breaking, the current behavior is non-standard and already inconsistent with zio-config. Users who worked around the bug (e.g., using some-key23value for someKey23Value) will need to update to some-key-23-value. So yeah, no pressure to merge.

@kitlangton kitlangton requested a review from Copilot June 2, 2025 12:37
@kitlangton kitlangton force-pushed the fix-kebab-and-snake-case branch from eb1ce0e to 94ad413 Compare June 2, 2025 12:37
Copy link

Copilot AI left a 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

Copy link
Contributor

@kyri-petrou kyri-petrou left a 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

hearnadam
hearnadam previously approved these changes Jun 4, 2025
@kitlangton kitlangton force-pushed the fix-kebab-and-snake-case branch from 3009bb2 to 1a50aad Compare June 4, 2025 17:45
hearnadam
hearnadam previously approved these changes Jun 4, 2025
Copy link
Contributor

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

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

Thanks!

@kyri-petrou kyri-petrou enabled auto-merge (squash) June 11, 2025 13:23
@kyri-petrou kyri-petrou merged commit fc55dac into zio:series/2.x Jun 12, 2025
19 checks passed
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.

4 participants