Skip to content

Conversation

@Adobels
Copy link

@Adobels Adobels commented Dec 16, 2025

Motivation

Add support for 1, 0, and YES, NO boolean strings in EnvironmentVariablesProvider. Support for YES and NO boolean strings was not discussed in the original issue. From personal experience, I found it interesting to include it. If rejected, I will remove it. I tried to remain consitent with the existing decoders and the way they are used by the provider.

Closes #110

Modifications

The EnvironmentVariablesProvider's bool decoder is configurable and can be initialized with support for true/false, 1/0, yes/no, or any combination of them.

Result

Usage of EnvironmentVariablesProvider has not changed, but by default all pairs of boolean strings are accepted when retrieving values as Bool or BoolArray. Client code can configure the provider to use a bool decoder with support only for true/false strings.

If it is more important to keep the behavior as it was, meaning default support for true/false only in the provider, then I will modify the default set for the EnvironmentVariablesProvider BoolDecoder.

Test Plan

The decoder is tested with dedicated tests, and additional tests for receiving a value from a provider were added to test the integration of BoolDecoder with EnvironmentVariablesProvider.

Code is commented, and tests are green locally.

@Adobels Adobels marked this pull request as draft December 16, 2025 16:07
@Adobels Adobels marked this pull request as ready for review December 16, 2025 16:14
@czechboy0
Copy link
Contributor

czechboy0 commented Dec 16, 2025

Thank you @Adobels! A few pieces of feedback:

  • I appreciate you future-proofing this by making the string-to-bool decoder customizable, but let's not add that to the API yet. We can always add it in the future, but for now please make it an implementation detail and hardcode to the logic you chose.
  • I do like supporting YES/NO as well, I don't expect this to cause confusion and many other systems support this too.
  • In the tests, please don't expand the default set of values, create a dedicated test that exhaustively tests these various Boolean variants.

And just FYI, I'm going on vacation so my responses will be slower until early January.

@Adobels Adobels marked this pull request as draft December 16, 2025 18:57
@Adobels Adobels marked this pull request as draft December 16, 2025 18:57
- Remove boolDecoder init customization
- Revert changes to the default set of values in tests
- Create a dedicated test to cover various string boolean variants
boolDecoderValuesForKeys -> valueForKeyOfBoolAndBoolArrayTypes
@Adobels
Copy link
Author

Adobels commented Dec 17, 2025

The stringToBool test iterates over cases and highlights the input, making it easy to identify a specific string that causes a problem. Tests/ConfigurationTests/ConfigBoolsFromStringDecoderTests.swift:31

Comments have been addressed, and the PR is ready for review.

@Adobels Adobels marked this pull request as ready for review December 17, 2025 10:20
@czechboy0 czechboy0 self-requested a review December 17, 2025 10:54
@Adobels Adobels marked this pull request as draft December 17, 2025 13:02
@Adobels
Copy link
Author

Adobels commented Dec 17, 2025

decodeBool is now part of EnvironmentVariablesProvider.Snapshot as a static member, to avoid a dependency on a Snapshot instance in tests.

decodeBool could be made private, but that would prevent direct unit tests and would require testing only through an EnvironmentVariablesProvider instance. If it is set to private, the two other decoders should be set to private as well.

I am ready for review.

@Adobels Adobels marked this pull request as ready for review December 17, 2025 13:09
@Adobels Adobels marked this pull request as draft December 17, 2025 18:08
Adobels and others added 3 commits December 17, 2025 19:09
…ntVariablesProvider.swift


Use a compact switch-based implementation for decodeBool.

Co-authored-by: Honza Dvorsky <honza@apple.com>
Fix the order of macros used in a test case to align with the test target order.

Co-authored-by: Honza Dvorsky <honza@apple.com>
@Adobels Adobels requested a review from czechboy0 December 17, 2025 20:31
@Adobels Adobels marked this pull request as ready for review December 17, 2025 20:32
@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Dec 18, 2025
@Adobels Adobels force-pushed the add-support-for-oneZero-and-yesNo-boolean-strings-in-EnvironementVariablesProvider branch from 6827154 to 75f7663 Compare December 18, 2025 17:36
…ro-and-yesNo-boolean-strings-in-EnvironementVariablesProvider
@Adobels Adobels force-pushed the add-support-for-oneZero-and-yesNo-boolean-strings-in-EnvironementVariablesProvider branch from 75f7663 to 22912a4 Compare December 18, 2025 17:39
@Adobels Adobels requested a review from czechboy0 December 18, 2025 17:41
@czechboy0
Copy link
Contributor

@Adobels seems the format check is still failing

@Adobels Adobels marked this pull request as draft December 19, 2025 08:39
@Adobels
Copy link
Author

Adobels commented Dec 19, 2025

@Adobels seems the format check is still failing

I have issues with a workflows included in the project localy and expected to have the full validation here.

@Adobels Adobels marked this pull request as ready for review December 19, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse 1 as a true Boolean in EnvironmentVariablesProvider

2 participants