Skip to content

Conversation

@czechboy0
Copy link
Contributor

@czechboy0 czechboy0 commented Oct 22, 2025

Motivation

While JSON and YAML support comes built-in in Swift Configuration, it should be easier to implement additional formats in external extension packages. Right now it required copying a lot of boilerplate code (thank you @finnvoor for pointing that out).

This PR is ready to land, the API was accepted in https://forums.swift.org/t/proposal-sco-0001-generic-file-providers/82824/9

Note that this PR isn't meant to land just yet - I'll first write a proposal to solicit community feedback before moving forward. However, you're encouraged to test it out by depending on my fork's branch with this feature, to ensure it works well - if you're considering extending Swift Configuration with a new format in your own package.

.package(
	url: "https://github.com/czechboy0/swift-configuration", 
	branch: "hd-generic-file-providers",
	traits: [.defaults, "ReloadingSupport"]
)

This PR also bumps the minimum Swift version to 6.2, since that's required by RawSpan.

Modifications

Refactors JSON and YAML providers to factor out reusable FileProvider and ReloadingFileProvider types that are generic over their snapshot type.

This reduces the amount of code an adopter has to write to add a new format only to the parsing logic, but they get everything else related to file reading and reloading for free.

Result

An API that allows adding more file formats much more easily.

Test Plan

Adapted tests.

@czechboy0
Copy link
Contributor Author

@finnvoor can you try this in your TOML package - does it help reduce the boilerplate?

@czechboy0 czechboy0 added the ⚠️ semver/major Breaks existing public API. label Oct 22, 2025
@czechboy0
Copy link
Contributor Author

The API break is expected, we're replacing the existing JSONProvider and YAMLProvider and their reloading variants.

@finnvoor
Copy link
Contributor

@czechboy0 🎉 it's much easier to implement a custom file provider now (finnvoor/swift-configuration-toml#1), I just copied over ConfigError / withConfigValueLookup, which are simple but may be nice to have public.

@czechboy0
Copy link
Contributor Author

Thanks for trying it out!

ConfigError will remain private, you should just throw your custom TOML error instead.

I'll look into whether to also make withConfigValueLookup public though.

@czechboy0 czechboy0 added 🆕 semver/minor Adds new public API. and removed ⚠️ semver/major Breaks existing public API. labels Nov 3, 2025
@czechboy0 czechboy0 changed the title [Experimental] Generic file providers Generic file providers (Implementation of SCO-0001) Nov 3, 2025
@czechboy0
Copy link
Contributor Author

Hitting a compiler crash, filed swiftlang/swift#85280

@czechboy0 czechboy0 marked this pull request as ready for review November 3, 2025 11:58
@czechboy0 czechboy0 requested a review from FranzBusch November 3, 2025 11:58
Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

LGTM. Just one question

@czechboy0 czechboy0 merged commit 183d866 into apple:main Nov 3, 2025
26 checks passed
@czechboy0 czechboy0 deleted the hd-generic-file-providers branch November 3, 2025 15:19
czechboy0 added a commit that referenced this pull request Nov 3, 2025
### Motivation

Check out the proposal text:
https://github.com/czechboy0/swift-configuration/blob/hd-sco-0001/Sources/Configuration/Documentation.docc/Proposals/SCO-0001.md

### Modifications

Added the proposal, the draft implementation can be found in
#60.

### Result

N/A

### Test Plan

N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor file providers to allow plugging in a format-specific parser + snapshot only

3 participants