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
- adding sample Vue frontend
- adding WireMock docker configuration for demo
- udpate README.md
<!-- Please describe your pull request here. -->
## References
- TODO
<!-- References to relevant GitHub issues and pull requests, esp.
upstream and downstream changes -->
## Submitter checklist
- [ ] Recommended: Join [WireMock Slack](https://slack.wiremock.org/) to
get any help in `#help-contributing` or a project-specific channel like
`#wiremock-java`
- [ ] The PR request is well described and justified, including the body
and the references
- [ ] The PR title represents the desired changelog entry
- [ ] The repository's code style is followed (see the contributing
guide)
- [ ] Test coverage that demonstrates that the change works as expected
- [ ] For new features, there's necessary documentation in this pull
request or in a subsequent PR to
[wiremock.org](https://github.com/wiremock/wiremock.org)
<!--
Put an `x` into the [ ] to show you have filled the information.
The template comes from
https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md
You can override it by creating .github/pull_request_template.md in your
own repository
-->
Using the extension with docker is similar to its usage with usage [standalone](#standalone): it just has to be available on
259
+
Using the extension with docker is similar to its usage with usage [standalone](#standalone): it just has to be available on
255
260
the classpath to be loaded automatically - it does not have to be added via `--extensions` .
256
261
257
262
**Note:** This extension depends on the current WireMock beta development, thus the tag `3x` has to be used:
258
263
259
-
260
264
```bash
261
265
docker run -it --rm \
262
266
-p 8080:8080 \
@@ -441,16 +445,18 @@ To append a state to a list:
441
445
442
446
### Accessing the previous state
443
447
444
-
You can use the `state` helper to temporarily access the previous state. Use the `state` helper in the same way as you would use it when you [retrieve a state](#retrieve-a-state).
448
+
You can use the `state` helper to temporarily access the previous state. Use the `state` helper in the same way as you would use it when
449
+
you [retrieve a state](#retrieve-a-state).
445
450
446
451
**Note:** This extension does not keep a history in itself but it's an effect of the evaluation order.
447
452
As templates are evaluated before the state is written, the state you access in `recordState` is the one before you store the new one
448
-
(so there might be none - you might want to use `default` for these cases). In case you have multiple `recordState``serveEventListeners`, you will have new states
453
+
(so there might be none - you might want to use `default` for these cases). In case you have multiple `recordState``serveEventListeners`, you will have new
454
+
states
449
455
being created in between, thus the previous state is the last stored one (so: not the one before the request).
450
456
451
457
1. listener 1 is executed
452
-
1. accesses state n
453
-
2. stores state n+1
458
+
1. accesses state n
459
+
2. stores state n+1
454
460
2. listener 2 is executed
455
461
1. accesses state n+1
456
462
2. stores state n+2
@@ -478,7 +484,6 @@ The evaluation order of listeners within a stub as well as across stubs is not g
478
484
}
479
485
```
480
486
481
-
482
487
## Deleting a state
483
488
484
489
Similar to recording a state, its deletion can be initiated in `serveEventListeners` of a stub.
@@ -528,50 +533,62 @@ Dictionary - only one option is interpreted (top to bottom as listed here)
528
533
-```json
529
534
{
530
535
"name": "deleteState",
531
-
"list": {
532
-
"deleteFirst": true
536
+
"parameters": {
537
+
"list": {
538
+
"deleteFirst": true
539
+
}
533
540
}
534
541
}
535
542
```
536
543
-```json
537
544
{
538
545
"name": "deleteState",
539
-
"list": {
540
-
"deleteLast": true
546
+
"parameters": {
547
+
"list": {
548
+
"deleteLast": true
549
+
}
541
550
}
542
551
}
543
552
```
544
553
-```json
545
554
{
546
555
"name": "deleteState",
547
-
"list": {
548
-
"deleteIndex": "1"
556
+
"parameters": {
557
+
"list": {
558
+
"deleteIndex": "1"
559
+
}
549
560
}
550
561
}
551
562
```
552
563
-```json
553
564
{
554
565
"name": "deleteState",
555
-
"list": {
556
-
"deleteIndex": "-1"
566
+
"parameters": {
567
+
"list": {
568
+
"deleteIndex": "-1"
569
+
}
557
570
}
558
571
}
559
572
```
560
573
-```json
561
574
{
562
575
"name": "deleteState",
563
-
"list": {
564
-
"deleteIndex": "{{request.pathSegments.[1]}}"
576
+
"parameters": {
577
+
"list": {
578
+
"deleteIndex": "{{request.pathSegments.[1]}}"
579
+
}
565
580
}
566
581
}
567
582
```
568
583
-```json
569
584
{
570
585
"name": "deleteState",
571
-
"list": {
572
-
"deleteWhere": {
573
-
"property": "myProperty",
574
-
"value": "{{request.pathSegments.[2]}}"
586
+
"parameters": {
587
+
"list": {
588
+
"deleteWhere": {
589
+
"property": "myProperty",
590
+
"value": "{{request.pathSegments.[2]}}"
591
+
}
575
592
}
576
593
}
577
594
}
@@ -763,7 +780,7 @@ The handler has the following parameters:
763
780
The number matches the one described in [Context update count match](#context-update-count-match)
764
781
-`property='listSize` retrieves the number of entries of `list`
765
782
-`property='list` get the whole list as array, e.g. to use it with [handlebars #each](https://handlebarsjs.com/guide/builtin-helpers.html#each)
766
-
- this property always has a default value (empty list), which can be overwritten with a JSON list
783
+
- this property always has a default value (empty list), which can be overwritten with a JSON list
767
784
-`list`: Getting an entry of the context's `list`, identified via a JSON path. Examples:
768
785
- getting the first state in the list: `list='[0].myProperty`
769
786
- getting the last state in the list: `list='[-1].myProperty`
@@ -774,7 +791,7 @@ You have to choose either `property` or `list` (otherwise, you will get a config
774
791
775
792
To retrieve a full body, use tripple braces: `{{{state context=request.pathSegments.[1] property='fullBody'}}}` .
776
793
777
-
When registering this extension, this helper is available via WireMock's [response templating](https://wiremock.org/3.x/docs/response-templating/) as well as
794
+
When registering this extension, this helper is available via WireMock's [response templating](https://wiremock.org/3.x/docs/response-templating/) as well as
778
795
in all configuration options of this extension.
779
796
780
797
### List operations
@@ -784,30 +801,60 @@ You can use [handlebars #each](https://handlebarsjs.com/guide/builtin-helpers.ht
784
801
Things to consider:
785
802
786
803
- this syntax only works with `body`. It DOES NOT work with `jsonBody`
787
-
- as this might get ugly, consider using `bodyFileName` / `withBodyFile()` have proper indentation
804
+
- as this might get ugly, consider using `bodyFileName` / `withBodyFile()` have proper indentation
788
805
- the default response for non-existant context as well as non-existant list in a context is an empty list. These states cannot be differentiated here
789
-
- if you still want a different response, consider using a [StateRequestMatcher](#negative-context-exists-match)
806
+
- if you still want a different response, consider using a [StateRequestMatcher](#negative-context-exists-match)
790
807
- the default value for this property has to be a valid JSON list - otherwise you will get an error log and the empty list response
791
808
- JSON does not allow trailing commas, so in order to create a valid JSON list, use `{{#unless @last}},{{/unless}` before `{{/each}}`
{{# each (state context='list' property='list' default='[]') }}
849
+
{
850
+
"id": {{id}},
851
+
"firstName": "{{firstName}}",
852
+
"lastName": "{{lastName}}"
853
+
}{{#unless @last}},{{/unless}}
854
+
{{/each}}
855
+
]
856
+
```
857
+
811
858
### Error handling
812
859
813
860
Missing Helper properties as well as unknown context properties are reported as error. WireMock renders them in the field, itself, so there won't be an
@@ -818,12 +865,13 @@ Example response with error:
818
865
```json
819
866
{
820
867
"id": "kn0ixsaswzrzcfzriytrdupnjnxor1is",
821
-
"firstName": "[ERROR: No state for context kn0ixsaswzrzcfzriytrdupnjnxor1is, property firstName found]",
868
+
"firstName": "[ERROR: No state for context 'kn0ixsaswzrzcfzriytrdupnjnxor1is', property 'firstName' found]",
822
869
"lastName": "Doe"
823
870
}
824
871
```
825
872
826
-
To avoid errors, you can specify a `default` for the state helper: `"clientId": "{{state context=request.pathSegments.[1] property='firstname' default='John'}}",`
873
+
To avoid errors, you can specify a `default` for the state
0 commit comments