Skip to content

Commit c069070

Browse files
committed
Merge branch 'main' into gemfille_lock_fix
2 parents 9309149 + 84096c2 commit c069070

File tree

2 files changed

+68
-96
lines changed

2 files changed

+68
-96
lines changed

documentation/dictionary.md

Lines changed: 65 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ nav_order: 8
1212
- [Basic Field Mapping](#basic-field-mapping)
1313
- [Nested Properties](#nested-properties)
1414
- [Handling Arrays](#handling-arrays)
15-
- [Referencing Elements Within the Array](#referencing-elements-within-the-array)
16-
- [Referencing the Entire Array](#referencing-the-entire-array)
1715
- [Nested properties in Arrays](#nested-properties-in-arrays)
1816
- [Referencing Other Schemas](#referencing-other-schemas)
1917
- [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
3836

3937
## Structure
4038

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.
4440
- Each entry in the dictionary maps a schema field to either a `single value` or a `list of values`.
4541
- If a single value is specified, it will be used directly.
4642
- 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:
6662
{% tabs dictionary %}
6763
{% tab dictionary yaml %}
6864
```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
7471
```
7572
{% endtab %}
7673
{% tab dictionary json %}
7774
```json
7875
{
79-
"Employee.name": "John",
80-
"Employee.age": [20, 30, 40]
76+
"Employee": {
77+
"name": "John",
78+
"age": [20, 30, 40]
79+
}
8180
}
8281
```
8382
{% endtab %}
@@ -88,7 +87,7 @@ Employee.age: # Multi-value
8887

8988
### Nested Properties
9089

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.
9291
For example, given the `Employee` schema as follows:
9392

9493
```yaml
@@ -115,68 +114,29 @@ Corresponding dictionary entries for the `first_name` and `last_name` property w
115114
{% tabs nestedProperty %}
116115
{% tab nestedProperty Single-Value %}
117116
```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
120121
```
121122
{% endtab %}
122123
{% tab nestedProperty Multi-Value %}
123124
```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
130133
```
131134
{% endtab %}
132135
{% endtabs %}
133136

134137
### Handling Arrays
135138

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
180140
For example, given the `Employee` schema as follows:
181141

182142
```yaml
@@ -198,19 +158,22 @@ Corresponding dictionary entries for the `aliases` array would be:
198158
{% tabs entireArray %}
199159
{% tab entireArray Single-Value %}
200160
```yaml
201-
Employee.aliases:
202-
- "John"
203-
- "Jane"
161+
Employee:
162+
aliases:
163+
- "John"
164+
- "Jane"
204165
```
205-
The entire array will be used directly
166+
The entire array will be used
206167
{% endtab %}
207168
{% tab entireArray Multi-Value %}
208169
```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"
212175
```
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
214177
{% endtab %}
215178
{% endtabs %}
216179

@@ -240,18 +203,22 @@ Corresponding dictionary entries for the `first_name` property within the `alias
240203
{% tabs nestedPropertyInArray %}
241204
{% tab nestedPropertyInArray Single-Value %}
242205
```yaml
243-
Employee.aliases[*].first_name: "John"
206+
Employee:
207+
aliases:
208+
- first_name: "John"
244209
```
245210
{% endtab %}
246211
{% tab nestedPropertyInArray Multi-Value %}
247212
```yaml
248-
Employee.aliases[*].first_name:
249-
- "John"
250-
- "Jane"
213+
Employee:
214+
aliases:
215+
- first_name: "John"
216+
- first_name: "Jane"
251217
```
252218
{% endtab %}
253219
{% 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.
255222

256223
### Referencing Other Schemas
257224

@@ -286,18 +253,20 @@ Corresponding dictionary entries for any property defined in the `Address` schem
286253
{% tabs nestedProperty %}
287254
{% tab nestedProperty Single-Value %}
288255
```yaml
289-
Address.city: "New York"
290-
Address.street: "Broadway"
256+
Address:
257+
city: "New York"
258+
street: "Broadway"
291259
```
292260
{% endtab %}
293261
{% tab nestedProperty Multi-Value %}
294262
```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"
301270
```
302271
{% endtab %}
303272
{% endtabs %}
@@ -371,9 +340,10 @@ components:
371340
Now create a dictionary file named `employees_dictionary.yaml` in the same directory:
372341

373342
```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"
377347
```
378348

379349
### Run the tests
@@ -520,11 +490,12 @@ schemas:
520490
Now create a dictionary file named `employees_dictionary.yaml` in the same directory:
521491

522492
```yaml
523-
Employee.id: 10
524-
Employee.name: Jamie
525-
Employee.employeeCode: pqrxyz
526-
Employee.department: Sales
527-
Employee.designation: Associate
493+
Employee:
494+
id: 10
495+
name: Jamie
496+
employeeCode: pqrxyz
497+
department: Sales
498+
designation: Associate
528499
```
529500

530501
### Run Service Virtualization

documentation/external_examples.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ Create a new example file in the `employee_details_examples` directory named `pa
314314
Create a new dictionary file in the root directory named `employee_details_dictionary.yaml` with the following contents:
315315

316316
```yaml
317-
Employee.id: 10
318-
Employee.employeeCode: EMP1234
317+
Employee:
318+
id: 10
319+
employeeCode: EMP1234
319320
```
320321
321322
#### Starting the Stub Server

0 commit comments

Comments
 (0)