Add ExpressibleByConfigStringArray support for string array–convertible types #149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #138
Motivation
Some configuration values are naturally represented as arrays of strings, but should be interpreted as a single domain type.
A common example is HTTP headers:
{ "headers": ["X-Foo: Bar", "X-Baz: Qux"] }Currently,
ExpressibleByConfigStringonly supports single string values, which makes it impossible for types likeHTTPHeadersto conform to it.This PR introduces a new protocol,
ExpressibleByConfigStringArray, to support types that require multiple strings for initialization while preserving the existingConfigReaderAPI patterns.Modifications
This PR introduces:
ConfigReaderAPIs for string-array-convertible types, following existing patterns:Each access pattern includes:
In total, 9 new APIs were added for
ExpressibleByConfigStringArray.ConfigReaderMethodTestsGet4ConfigReaderMethodTestsFetch4ConfigReaderMethodTestsWatch4The tests cover:
No existing APIs were modified.
Result
After this change, configuration values defined as arrays of strings can be directly converted into domain types (example key: "headers"):
This enables cleaner configuration modeling for types like HTTP headers, while keeping the API consistent and backward-compatible.
Test Plan
swift testAll tests pass successfully.
Notes
This is my first contribution to SwiftConfiguration.
I’d really appreciate any feedback on the API design or naming choices.