Skip to content

Commit 728b529

Browse files
Merge pull request #1064 from Gijsreyn/fix/reference-docs-array
Fix examples for array functions
2 parents 1f01635 + b97399a commit 728b529

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

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

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,31 @@ title: array
99

1010
## Synopsis
1111

12-
Creates an array from the given elements (strings, numbers, arrays, or objects).
12+
Wraps a single value (string, number, array, or object) in an array.
1313

1414
## Syntax
1515

1616
```Syntax
17-
array(<element1>, <element2>, ...)
17+
array(<value>)
1818
```
1919

2020
## Description
2121

22-
The `array()` function creates an array from the provided arguments, allowing
23-
mixed data types within the same array. Unlike `createArray()` which requires
24-
all elements to be the same type, `array()` accepts any combination of strings,
25-
numbers, arrays, and objects as arguments.
22+
The `array()` function returns a new array containing the single input value.
23+
The value can be a string, number, array, or object. Use
24+
`createArray()` to construct arrays with multiple elements of the same type.
2625

27-
This function is useful when you need to combine different types of data into a
28-
single collection, such as mixing configuration values, computed results, and
29-
structured metadata in deployment scenarios.
26+
This function is useful when a schema expects an array, but you only have a
27+
single value, or when you need to nest an existing array or object inside an
28+
outer array.
3029

3130
## Examples
3231

33-
### Example 1 - Build a deployment plan
32+
### Example 1 - Wrap an existing array as a single element
3433

35-
This example demonstrates combining different data types to create a comprehensive
36-
deployment configuration. The array contains an existing server list, a numeric
37-
batch size, and a configuration object with deployment strategy details.
34+
This example demonstrates wrapping an existing server list into a single array
35+
element, producing a nested array. This can be useful when a downstream schema
36+
expects an array of arrays.
3837

3938
```yaml
4039
# array.example.1.dsc.config.yaml
@@ -52,7 +51,7 @@ resources:
5251
- name: Deployment Plan
5352
type: Microsoft.DSC.Debug/Echo
5453
properties:
55-
output: "[array(parameters('webServers'), parameters('batchSize'), createObject('strategy', 'blue-green'))]"
54+
output: "[array(parameters('webServers'))]"
5655
```
5756
5857
```bash
@@ -68,17 +67,14 @@ results:
6867
output:
6968
- - web01
7069
- web02
71-
- 2
72-
- strategy: blue-green
7370
messages: []
7471
hadErrors: false
7572
```
7673
77-
### Example 2 - Compose mixed telemetry payload parts
74+
### Example 2 - Wrap a single object for payloads
7875
79-
This example shows how to construct a telemetry payload by combining a string
80-
identifier, structured metadata object, and numeric status code into a single
81-
array for logging or monitoring systems.
76+
This example shows how to wrap a structured metadata object into an array for
77+
logging or monitoring systems that expect arrays.
8278
8379
```yaml
8480
# array.example.2.dsc.config.yaml
@@ -92,7 +88,7 @@ resources:
9288
type: Microsoft.DSC.Debug/Echo
9389
properties:
9490
output:
95-
payload: "[array(parameters('correlationId'), createObject('severity', 'info'), 200)]"
91+
payload: "[array(createObject('severity', 'info'))]"
9692
```
9793
9894
```bash
@@ -107,18 +103,15 @@ results:
107103
actualState:
108104
output:
109105
payload:
110-
- ABC123
111106
- severity: info
112-
- 200
113107
messages: []
114108
hadErrors: false
115109
```
116110
117-
### Example 3 - Combine generated and literal collections
111+
### Example 3 - Wrap generated collections
118112
119-
This example demonstrates nesting arrays and objects within a parent array,
120-
showing how `array()` can combine results from other DSC functions like
121-
`createArray()` and `createObject()` with literal values.
113+
This example demonstrates wrapping a generated collection (like one from
114+
`createArray()` or `createObject()`) into an outer array.
122115

123116
```yaml
124117
# array.example.3.dsc.config.yaml
@@ -128,7 +121,8 @@ resources:
128121
type: Microsoft.DSC.Debug/Echo
129122
properties:
130123
output:
131-
combined: "[array(createArray('a','b'), array(1,2), createObject('k','v'))]"
124+
combinedArray: "[array(createArray('a','b'))]"
125+
combinedObject: "[array(createObject('k','v'))]"
132126
```
133127

134128
```bash
@@ -142,31 +136,31 @@ results:
142136
result:
143137
actualState:
144138
output:
145-
combined:
139+
combinedArray:
146140
- - a
147141
- b
148-
- - 1
149-
- 2
142+
combinedObject:
150143
- k: v
151144
messages: []
152145
hadErrors: false
153146
```
154147

155148
## Parameters
156149

157-
### element1, element2, ...
150+
### value
158151

159-
The elements to include in the array.
152+
The single value to wrap in the array.
160153

161154
```yaml
162155
Type: string, number, array, or object
163156
Required: false
164-
Multiplicity: 0 or more
157+
MinimumCount: 1
158+
MaximumCount: 1
165159
```
166160

167-
Each element provided as an argument will be added to the resulting array in the
168-
order specified. All elements must be one of the four accepted types: string,
169-
number (integer), array, or object. Boolean and null values are not supported.
161+
The provided value will be wrapped into the resulting array. The value must be
162+
one of the four accepted types: string, number (integer), array, or object.
163+
Boolean and null values are not supported.
170164

171165
## Output
172166

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ hadErrors: false
109109
### Example 3 - Chain with array construction
110110
111111
This example shows how `first()` can be combined with `array()` to get the
112-
first element from a dynamically constructed array containing mixed data types.
112+
first element from a dynamically constructed array, by wrapping a single
113+
generated collection.
113114

114115
```yaml
115116
# first.example.3.dsc.config.yaml
@@ -119,7 +120,7 @@ resources:
119120
type: Microsoft.DSC.Debug/Echo
120121
properties:
121122
output:
122-
firstMixed: "[first(array(createArray('a','b'), createObject('k','v')))]"
123+
firstMixed: "[first(array(createArray('a','b')))]"
123124
```
124125

125126
```bash
@@ -133,9 +134,7 @@ results:
133134
result:
134135
actualState:
135136
output:
136-
firstMixed:
137-
- a
138-
- b
137+
firstMixed: a
139138
messages: []
140139
hadErrors: false
141140
```

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ resources:
9494
type: Microsoft.DSC.Debug/Echo
9595
properties:
9696
output:
97-
hasFeature: "[indexOf(array(createObject('name','Preview'), createObject('name','Beta')), createObject('name','Beta'))]"
97+
hasFeature: "[indexOf(array(createObject('name','Beta')), createObject('name','Beta'))]"
9898
```
9999
100100
```bash
@@ -108,7 +108,7 @@ results:
108108
result:
109109
actualState:
110110
output:
111-
hasFeature: 1
111+
hasFeature: 0
112112
messages: []
113113
hadErrors: false
114114
```

0 commit comments

Comments
 (0)