Skip to content

Document ConfigKeySource.allCases ordering as a stable API contract #2

@leogdion

Description

@leogdion

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:

  1. 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.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions