Skip to content

swift-configuration decoder#1447

Open
noah-thor wants to merge 3 commits intoapple:mainfrom
noah-thor:swift-config-decoder
Open

swift-configuration decoder#1447
noah-thor wants to merge 3 commits intoapple:mainfrom
noah-thor:swift-config-decoder

Conversation

@noah-thor
Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

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

  • Tested locally
  • Added/updated tests
  • Added/updated docs

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.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Apr 24, 2026
Comment thread NOTICE.md
## 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 )**
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure what the correct format is for the license in the notice

Comment on lines +30 to +33
public protocol ConfigEncodingStrategy: Sendable {
associatedtype Value: Encodable
func encode(_ value: Value, to encoder: Encoder) throws
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not currently used, but seemed like it could be handy in the future, making any config conform to ConfigCodingStrategy

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."
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could add some of this functionality if we have a use case

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant