Skip to content

Commit 0b47bd9

Browse files
committed
Add string example
1 parent 5d37022 commit 0b47bd9

File tree

1 file changed

+64
-0
lines changed
  • docs/reference/schemas/config/functions

1 file changed

+64
-0
lines changed

docs/reference/schemas/config/functions/union.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,59 @@ messages: []
200200
hadErrors: false
201201
```
202202
203+
### Example 5 - Union with string conversion for logging
204+
205+
The following example shows how to use union with string conversion for
206+
building comprehensive log messages.
207+
208+
```yaml
209+
# union.example.5.dsc.config.yaml
210+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
211+
parameters:
212+
baseLogData:
213+
type: object
214+
defaultValue:
215+
timestamp: 1691596800
216+
level: "INFO"
217+
requestData:
218+
type: object
219+
defaultValue:
220+
requestId: 12345
221+
method: "GET"
222+
responseData:
223+
type: object
224+
defaultValue:
225+
statusCode: 200
226+
duration: 150
227+
resources:
228+
- name: Build comprehensive log entry
229+
type: Microsoft.DSC.Debug/Echo
230+
properties:
231+
output:
232+
logEntry: "[string(union(parameters('baseLogData'), parameters('requestData'), parameters('responseData')))]"
233+
logArray: "[union(createArray('timestamp'), createArray('level', 'requestId'))]"
234+
```
235+
236+
```bash
237+
dsc config get --file union.example.5.dsc.config.yaml
238+
```
239+
240+
```yaml
241+
results:
242+
- name: Build comprehensive log entry
243+
type: Microsoft.DSC.Debug/Echo
244+
result:
245+
actualState:
246+
output:
247+
logEntry: '{"timestamp":1691596800,"level":"INFO","requestId":12345,"method":"GET","statusCode":200,"duration":150}'
248+
logArray:
249+
- timestamp
250+
- level
251+
- requestId
252+
messages: []
253+
hadErrors: false
254+
```
255+
203256
## Parameters
204257
205258
### collection1
@@ -247,4 +300,15 @@ input collections.
247300
Type: [array, object]
248301
```
249302

303+
## Related functions
304+
305+
- [`createArray()`][00] - Creates arrays that can be combined with union
306+
- [`createObject()`][01] - Creates objects that can be merged with union
307+
- [`string()`][02] - Converts objects or arrays to JSON strings
308+
- [`concat()`][03] - Concatenates arrays (alternative to union for arrays)
309+
250310
<!-- Link reference definitions -->
311+
[00]: ./createArray.md
312+
[01]: ./createObject.md
313+
[02]: ./string.md
314+
[03]: ./concat.md

0 commit comments

Comments
 (0)