swift-configuration decoder#1447
Open
noah-thor wants to merge 3 commits intoapple:mainfrom
Open
Conversation
This adds a swift Decoder that decodes from a swift-configuration ConfigSnapshot.
This adds the ability to modify how select types are decoded within the ConfigSnapshotDecoder. This is something that JSONEncoder already does with URLs specifically, however this enables users to configure this behavior for any arbitrary type regardless of existing Codable conformance.
noah-thor
commented
Apr 24, 2026
| ## Runtime Library Exception to the Apache 2.0 License: ## | ||
| As an exception, if you use this Software to compile your source code and portions of this Software are embedded into the binary product as a result, you may redistribute such product without providing attribution as would otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. | ||
|
|
||
| **Apple Inc. and the SwiftConfiguration project authors ( swift-configuration )** |
Contributor
Author
There was a problem hiding this comment.
Not sure what the correct format is for the license in the notice
noah-thor
commented
Apr 24, 2026
Comment on lines
+30
to
+33
| public protocol ConfigEncodingStrategy: Sendable { | ||
| associatedtype Value: Encodable | ||
| func encode(_ value: Value, to encoder: Encoder) throws | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Not currently used, but seemed like it could be handy in the future, making any config conform to ConfigCodingStrategy
noah-thor
commented
Apr 24, 2026
| DecodingError.Context( | ||
| codingPath: codingPath, | ||
| debugDescription: | ||
| "ConfigSnapshotDecoder does not support decoding arrays of \(T.self). Only arrays of primitive types (String, Int, Double, Bool) are supported." |
Contributor
Author
There was a problem hiding this comment.
We could add some of this functionality if we have a use case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Type of Change
Motivation and Context
This adds a swift Decoder that decodes from a swift-configuration
ConfigSnapshot, and adds the ability to modify how select types are decoded within the
ConfigSnapshotDecoder. This is something that JSONEncoder already does
with URLs specifically, however this enables users to configure this
behavior for any arbitrary type regardless of existing Codable
conformance.
The decoder will help us expand on top of (pr: #1425), which switches user configuration to TOML. With this PR we will be able to provide a multi layered TOML if desired, allowing container to ship a default TOML instead of encoding them in code constants.
Testing