Skip to content

Commit af88704

Browse files
authored
[Docs] Fixup context docs (#90)
### Motivation As part of #71, we removed the string-based overrides, which had `context` as a parameter. Now the way to pass context is to explicitly construct a `ConfigKey`. The original PR missed updating these docs. ### Modifications Updated stale docs to be accurate. ### Result Accurate docs. ### Test Plan N/A
1 parent 5ae6bf8 commit af88704

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

Sources/Configuration/Documentation.docc/Guides/Choosing-access-patterns.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ let timeout = try await config.fetchInt(forKey: "http.timeout", default: 30)
6060

6161
// Fetch with context for environment-specific configuration
6262
let dbConnectionString = try await config.fetchRequiredString(
63-
forKey: "database.url",
64-
context: [
65-
"environment": "production",
66-
"region": "us-west-2",
67-
"service": "user-service"
68-
],
63+
forKey: ConfigKey(
64+
"database.url",
65+
context: [
66+
"environment": "production",
67+
"region": "us-west-2",
68+
"service": "user-service"
69+
]
70+
),
6971
isSecret: true
7072
)
7173
```
@@ -145,15 +147,19 @@ let context: [String: ConfigContextValue] = [
145147

146148
// Get environment-specific database configuration
147149
let dbConfig = try await config.fetchRequiredString(
148-
forKey: "database.connection_string",
149-
context: context,
150+
forKey: ConfigKey(
151+
"database.connection_string",
152+
context: context,
153+
)
150154
isSecret: true
151155
)
152156

153157
// Watch for region-specific timeout adjustments
154158
try await config.watchInt(
155-
forKey: "api.timeout",
156-
context: ["region": "us-west-2"],
159+
forKey: ConfigKey(
160+
"api.timeout",
161+
context: ["region": "us-west-2"]
162+
),
157163
default: 5000
158164
) { updates in
159165
for await timeout in updates {

Sources/Configuration/Documentation.docc/Guides/Choosing-reader-methods.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,27 @@ All variants support the same additional features:
208208
```swift
209209
// Optional with context
210210
let timeout = config.int(
211-
forKey: "service.timeout",
212-
context: ["environment": "production", "region": "us-east-1"]
211+
forKey: ConfigKey(
212+
"service.timeout",
213+
context: ["environment": "production", "region": "us-east-1"]
214+
)
213215
)
214216

215217
// Default with context
216218
let timeout = config.int(
217-
forKey: "service.timeout",
218-
context: ["environment": "production"],
219+
forKey: ConfigKey(
220+
"service.timeout",
221+
context: ["environment": "production"]
222+
),
219223
default: 30
220224
)
221225

222226
// Required with context
223227
let timeout = try config.requiredInt(
224-
forKey: "service.timeout",
225-
context: ["environment": "production"]
228+
forKey: ConfigKey(
229+
"service.timeout",
230+
context: ["environment": "production"]
231+
)
226232
)
227233
```
228234

Sources/Configuration/Documentation.docc/Guides/Using-in-memory-providers.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ With a provider configured this way, a config reader will return the following r
6969
let config = ConfigReader(provider: provider)
7070
config.double(forKey: "http.client.timeout") // nil
7171
config.double(
72-
forKey: "http.client.timeout",
73-
context: ["upstream": "example1.org"]
72+
forKey: ConfigKey(
73+
"http.client.timeout",
74+
context: ["upstream": "example1.org"]
75+
)
7476
) // 15.0
7577
config.double(
76-
forKey: "http.client.timeout",
77-
context: ["upstream": "example2.org"]
78+
forKey: ConfigKey(
79+
"http.client.timeout",
80+
context: ["upstream": "example2.org"]
81+
)
7882
) // 30.0
7983
```
8084

0 commit comments

Comments
 (0)