Skip to content

Conversation

@czechboy0
Copy link
Contributor

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).

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"]
)

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.

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

Labels

⚠️ semver/major Breaks existing 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

2 participants