Background
Downstream consumers iterate ConfigKeySource.allCases and treat the iteration order as a precedence list (e.g. CLI → ENV). See CelestraCloud's ConfigurationLoader.read(_:) overloads:
for source in ConfigKeySource.allCases {
guard let keyString = key.key(for: source) else { continue }
if let value = readString(forKey: keyString) { return value }
}
Today this works because Swift's CaseIterable synthesizes allCases in declaration order, but that order is not currently documented as part of ConfigKeySource's public contract. Reordering the enum cases would silently flip precedence at every consumer with no compile-time or test-time signal.
Proposal
Pick one of:
- Document the ordering as a stable contract. Add an API-level doc comment to
ConfigKeySource (or its CaseIterable conformance) stating that allCases is ordered by precedence, highest first, and that case order is part of the public API.
- Expose an explicit precedence API. Add a dedicated
static var priority: [ConfigKeySource] (or similar) so consumers iterate that instead of allCases. Decouples precedence from declaration order entirely.
Option 2 is sturdier; option 1 is cheaper if the project is comfortable making ordering a SemVer-relevant contract.
Context
Surfaced during code review of brightdigit/MistKit#406 (finding #1).
Companion downstream tracker will be opened in brightdigit/CelestraCloud to add a defensive comment until the contract is documented.
Background
Downstream consumers iterate
ConfigKeySource.allCasesand treat the iteration order as a precedence list (e.g. CLI → ENV). See CelestraCloud'sConfigurationLoader.read(_:)overloads:Today this works because Swift's
CaseIterablesynthesizesallCasesin declaration order, but that order is not currently documented as part ofConfigKeySource's public contract. Reordering the enum cases would silently flip precedence at every consumer with no compile-time or test-time signal.Proposal
Pick one of:
ConfigKeySource(or itsCaseIterableconformance) stating thatallCasesis ordered by precedence, highest first, and that case order is part of the public API.static var priority: [ConfigKeySource](or similar) so consumers iterate that instead ofallCases. Decouples precedence from declaration order entirely.Option 2 is sturdier; option 1 is cheaper if the project is comfortable making ordering a SemVer-relevant contract.
Context
Surfaced during code review of brightdigit/MistKit#406 (finding #1).
Companion downstream tracker will be opened in
brightdigit/CelestraCloudto add a defensive comment until the contract is documented.