You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/dictionary.md
+65-94Lines changed: 65 additions & 94 deletions
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,6 @@ nav_order: 8
12
12
-[Basic Field Mapping](#basic-field-mapping)
13
13
-[Nested Properties](#nested-properties)
14
14
-[Handling Arrays](#handling-arrays)
15
-
-[Referencing Elements Within the Array](#referencing-elements-within-the-array)
16
-
-[Referencing the Entire Array](#referencing-the-entire-array)
17
15
-[Nested properties in Arrays](#nested-properties-in-arrays)
18
16
-[Referencing Other Schemas](#referencing-other-schemas)
19
17
-[Dictionary with Contract Testing](#dictionary-with-contract-testing)
@@ -38,9 +36,7 @@ The dictionary can be supplied in either `YAML` or `JSON` format and should adhe
38
36
39
37
## Structure
40
38
41
-
The dictionary defines a mapping where keys represent schema fields using a syntax similar to `JSONPath`.
42
-
This structured approach enables precise field references within complex objects.
43
-
39
+
The dictionary utilizes a standard JSON format, where fields are represented as nested properties that reflect the hierarchical structure of the schema.
44
40
- Each entry in the dictionary maps a schema field to either a `single value` or a `list of values`.
45
41
- If a single value is specified, it will be used directly.
46
42
- If a list is specified, one value will be `pseudo-randomly` selected.
@@ -66,18 +62,21 @@ Corresponding dictionary entries for the `name` and `age` properties would be:
66
62
{% tabs dictionary %}
67
63
{% tab dictionary yaml %}
68
64
```yaml
69
-
Employee.name: John # Single-value
70
-
Employee.age: # Multi-value
71
-
- 20
72
-
- 30
73
-
- 40
65
+
Employee:
66
+
name: John # Single-value
67
+
age: # Multi-value
68
+
- 20
69
+
- 30
70
+
- 40
74
71
```
75
72
{% endtab %}
76
73
{% tab dictionary json %}
77
74
```json
78
75
{
79
-
"Employee.name": "John",
80
-
"Employee.age": [20, 30, 40]
76
+
"Employee": {
77
+
"name": "John",
78
+
"age": [20, 30, 40]
79
+
}
81
80
}
82
81
```
83
82
{% endtab %}
@@ -88,7 +87,7 @@ Employee.age: # Multi-value
88
87
89
88
### Nested Properties
90
89
91
-
When working with nested structures, the key is extended using the `.` character as a separator to represent the hierarchy of properties.<br/>
90
+
For nested structures, properties are represented as nested keys, where each level corresponds to a that level in the schema hierarchy.
92
91
For example, given the `Employee` schema as follows:
93
92
94
93
```yaml
@@ -115,68 +114,29 @@ Corresponding dictionary entries for the `first_name` and `last_name` property w
115
114
{% tabs nestedProperty %}
116
115
{% tab nestedProperty Single-Value %}
117
116
```yaml
118
-
Employee.name.first_name: John
119
-
Employee.name.last_name: Smith
117
+
Employee:
118
+
name:
119
+
first_name: John
120
+
last_name: Smith
120
121
```
121
122
{% endtab %}
122
123
{% tab nestedProperty Multi-Value %}
123
124
```yaml
124
-
Employee.name.first_name:
125
-
- John
126
-
- Jane
127
-
Employee.name.last_name:
128
-
- Smith
129
-
- Doe
125
+
Employee:
126
+
name:
127
+
first_name:
128
+
- John
129
+
- Jane
130
+
last_name:
131
+
- Smith
132
+
- Doe
130
133
```
131
134
{% endtab %}
132
135
{% endtabs %}
133
136
134
137
### Handling Arrays
135
138
136
-
For properties that are arrays, two referencing styles are supported, referencing the entire array or referencing elements within the array.<br/>
137
-
**Note:**: If both are specified, the key referencing the entire array will be used.
138
-
139
-
#### Referencing Elements Within the Array
140
-
141
-
To reference elements within an array, the key should be appended with `[*]`.<br/>
142
-
For instance, consider the following `Employee` schema:
143
-
144
-
```yaml
145
-
components:
146
-
schemas:
147
-
Employee:
148
-
type: object
149
-
required:
150
-
- aliases
151
-
properties:
152
-
aliases:
153
-
type: array
154
-
items:
155
-
type: string
156
-
```
157
-
158
-
Corresponding dictionary entries for elements within the `aliases` array would be:
159
-
160
-
{% tabs ElemWithinArray %}
161
-
{% tab ElemWithinArray Single-Value %}
162
-
```yaml
163
-
Employee.aliases[*]: John
164
-
```
165
-
The same value is repeated for each elements in the array.
166
-
{% endtab %}
167
-
{% tab ElemWithinArray Multi-Value %}
168
-
```yaml
169
-
Employee.aliases[*]:
170
-
- John
171
-
- Jane
172
-
```
173
-
For each element in the array, a value is `pseudo-randomly` selected from the list.
174
-
{% endtab %}
175
-
{% endtabs %}
176
-
177
-
#### Referencing the Entire Array
178
-
179
-
To reference the entire array, simply omit `[*]` from the key.<br/>
139
+
For properties that are arrays, the values must also be an array in the dictionary
180
140
For example, given the `Employee` schema as follows:
181
141
182
142
```yaml
@@ -198,19 +158,22 @@ Corresponding dictionary entries for the `aliases` array would be:
198
158
{% tabs entireArray %}
199
159
{% tab entireArray Single-Value %}
200
160
```yaml
201
-
Employee.aliases:
202
-
- "John"
203
-
- "Jane"
161
+
Employee:
162
+
aliases:
163
+
- "John"
164
+
- "Jane"
204
165
```
205
-
The entire array will be used directly
166
+
The entire array will be used
206
167
{% endtab %}
207
168
{% tab entireArray Multi-Value %}
208
169
```yaml
209
-
Employee.aliases:
210
-
- ["John", "Jane"]
211
-
- ["May", "Jones"]
170
+
Employee:
171
+
aliases:
172
+
- ["John", "Jane"] # JSON style array
173
+
- - "May" # YAML style array
174
+
- "Jones"
212
175
```
213
-
One of the nested arrays will be `pseudo-randomly` selected and used directly
176
+
One of the nested arrays will be `pseudo-randomly` selected and used
214
177
{% endtab %}
215
178
{% endtabs %}
216
179
@@ -240,18 +203,22 @@ Corresponding dictionary entries for the `first_name` property within the `alias
240
203
{% tabs nestedPropertyInArray %}
241
204
{% tab nestedPropertyInArray Single-Value %}
242
205
```yaml
243
-
Employee.aliases[*].first_name: "John"
206
+
Employee:
207
+
aliases:
208
+
- first_name: "John"
244
209
```
245
210
{% endtab %}
246
211
{% tab nestedPropertyInArray Multi-Value %}
247
212
```yaml
248
-
Employee.aliases[*].first_name:
249
-
- "John"
250
-
- "Jane"
213
+
Employee:
214
+
aliases:
215
+
- first_name: "John"
216
+
- first_name: "Jane"
251
217
```
252
218
{% endtab %}
253
219
{% endtabs %}
254
-
> **Note:** This nesting behaves correctly because `first_name` is not defined as a top-level property in the schema
220
+
> **Note:** This nesting behaves correctly because `first_name` is not defined as a top-level property in the schema.
221
+
> It is also not necessary to specify all properties of the object within the array, any missing properties will be populated by Specmatic.
255
222
256
223
### Referencing Other Schemas
257
224
@@ -286,18 +253,20 @@ Corresponding dictionary entries for any property defined in the `Address` schem
286
253
{% tabs nestedProperty %}
287
254
{% tab nestedProperty Single-Value %}
288
255
```yaml
289
-
Address.city: "New York"
290
-
Address.street: "Broadway"
256
+
Address:
257
+
city: "New York"
258
+
street: "Broadway"
291
259
```
292
260
{% endtab %}
293
261
{% tab nestedProperty Multi-Value %}
294
262
```yaml
295
-
Address.city:
296
-
- "New York"
297
-
- "London"
298
-
Address.street:
299
-
- "Broadway"
300
-
- "High Street"
263
+
Address:
264
+
city:
265
+
- "New York"
266
+
- "London"
267
+
street:
268
+
- "Broadway"
269
+
- "High Street"
301
270
```
302
271
{% endtab %}
303
272
{% endtabs %}
@@ -371,9 +340,10 @@ components:
371
340
Now create a dictionary file named `employees_dictionary.yaml` in the same directory:
372
341
373
342
```yaml
374
-
EmployeeDetails.name: John Doe
375
-
EmployeeDetails.department: IT
376
-
EmployeeDetails.employeeCode: "12345"
343
+
EmployeeDetails:
344
+
name: John Doe
345
+
department: IT
346
+
employeeCode: "12345"
377
347
```
378
348
379
349
### Run the tests
@@ -520,11 +490,12 @@ schemas:
520
490
Now create a dictionary file named `employees_dictionary.yaml` in the same directory:
0 commit comments