Skip to content

Commit c8af26e

Browse files
authored
[Docs] Fix up docs around key mapping (#46)
### Motivation The docs had an incorrect name for `KeyMappingProvider`, plus they didn't really show how to use the convenience methods. ### Modifications Fixed the name and added examples of the convenience method. ### Result Improved docs. ### Test Plan Previewed locally.
1 parent 4a50528 commit c8af26e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/Configuration/Providers/Wrappers/KeyMappingProvider.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
///
2929
/// ## Example
3030
///
31-
/// Use `MappedKeyProvider` when you want to map keys for specific providers in a multi-provider
31+
/// Use `KeyMappingProvider` when you want to map keys for specific providers in a multi-provider
3232
/// setup:
3333
///
3434
/// ```swift
@@ -49,6 +49,18 @@
4949
/// // This reads from "MYAPP_PROD_DATABASE_HOST" env var or "database.host" in JSON
5050
/// let host = config.string(forKey: "database.host", default: "localhost")
5151
/// ```
52+
///
53+
/// ## Convenience method
54+
///
55+
/// You can also use the ``ConfigProvider/prefixKeys(with:)`` convenience method on
56+
/// configuration provider types to wrap one in a ``KeyMappingProvider``:
57+
///
58+
/// ```swift
59+
/// let envProvider = EnvironmentVariablesProvider()
60+
/// let keyMappedEnvProvider = envProvider.mapKeys { key in
61+
/// key.prepending(["myapp", "prod"])
62+
/// }
63+
/// ```
5264
public struct KeyMappingProvider<Upstream: ConfigProvider>: Sendable {
5365
/// The mapping function applied to each key before a lookup.
5466
private let mapKey: @Sendable (AbsoluteConfigKey) -> AbsoluteConfigKey

0 commit comments

Comments
 (0)