Vance Jo
04/16/2024, 3:32 PM"arrayName": [
"{{#each (jsonPath request.body '$.[0].arrayName') as |node|}}",
{
"type": "{{node.type}}",
"value": "{{node.value}}"
},
"{{/each}}"
]
But this result is like that.
"arrayName": [
"",
{
"type": "aaa",
"value": "bbb"
}
"",
{
"type": "ccc",
"value": "ddd"
},
""
]
Lee Turner
04/16/2024, 3:47 PM"
around the each
template partLee Turner
04/16/2024, 3:48 PM,
on the last object in the array because if it is there it won't be valid jsonLee Turner
04/16/2024, 3:50 PM"arrayName": [
{{#each (jsonPath request.body '$.[0].arrayName') as |node|}}
{
"type": "{{node.type}}",
"value": "{{node.value}}"
}{{#not @last}},{{/not}}
{{/each}}
]
Lee Turner
04/16/2024, 3:53 PMVance Jo
04/16/2024, 10:46 PM"
, the Wiremock server(I used a standalone server) occurs error.
wiremock | Exception in thread "main" com.github.tomakehurst.wiremock.standalone.MappingFileException: Error loading file /home/wiremock/./mappings/NAC/post-nimbus-servicesapidedupe-1ef9c420-34f4-4e35-8f0a-501adab822bb.json:
wiremock | Unexpected character ('{' (code 123)): was expecting double-quote to start field name
wiremock | at [Source: (byte[])"{
wiremock | }"[truncated 2599 bytes]; line: 58, column: 26]
wiremock | at com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource.loadMappingsInto(JsonFileMappingsSource.java:145)
wiremock | at com.github.tomakehurst.wiremock.core.WireMockApp.loadMappingsUsing(WireMockApp.java:294)
wiremock | at com.github.tomakehurst.wiremock.core.WireMockApp.loadDefaultMappings(WireMockApp.java:287)
wiremock | at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:143)
wiremock | at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:74)
wiremock | at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:72)
wiremock | at wiremock.Run.main(Run.java:23)
Lee Turner
04/17/2024, 7:53 AMVance Jo
04/17/2024, 7:54 AM"transformers": [
"response-template"
]
Lee Turner
04/17/2024, 7:58 AMVance Jo
04/17/2024, 8:03 AM{
"uuid": "1ef9c420-34f4-4e35-8f0a-501adab822bb",
"persistent": true,
"request": {
"urlPathPattern": "/test/url",
"method": "POST",
"headers": {
"Accept": {
"contains": "application/json"
}
},
"bodyPatterns": [
{
"matchesJsonSchema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"paramA": {
"type": "string",
"pattern": "[0-9]+"
},
"paramB": {
"type": "string",
"pattern": "[0-9]{6}"
},
"paramC": {
"type": "string",
"pattern": "[0-9]{10}"
},
"paramD": {
"type": "string"
},
"paramE": {
"type": "string"
},
"paramF": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
}
}
}
]
},
"response": {
"status": 200,
"jsonBody": [
{
"dedupeRequestSource": {
"paramA": "{{jsonPath request.body '$.[0].paramA'}}",
"paramB": "{{jsonPath request.body '$.[0].paramB'}}",
"paramC": "{{jsonPath request.body '$.[0].paramC'}}",
"paramD": "{{jsonPath request.body '$.[0].paramD'}}",
"paramF": [
"{{#each (jsonPath request.body '$.[0].paramF') as |node|}}",
{
"type": "{{node.type}}",
"value": "{{node.value}}"
},
"{{/each}}"
],
"paramE": "{{jsonPath request.body '$.[0].paramE'}}"
},
"results": [],
"type": "PRIMARY",
"dedupeReferenceId": "{{randomValue length=16 type='NUMERIC'}}",
"dedupePresent": false,
"invalidDedupeResponse": false
}
],
"headers": {
"Content-Type": "application/json"
},
"transformers": [
"response-template"
]
}
}
Lee Turner
04/17/2024, 8:07 AM"
round everything. I think the example I gave you is correct but you will have to use body
instead of jsonBody
which unfortunately means you will have to escape everything in the response body.
The other option is to pull out the response body into a separate file and reference it via the bodyFileName
element. You can find more about that here - https://wiremock.org/docs/response-templating/Lee Turner
04/17/2024, 8:09 AMVance Jo
04/17/2024, 8:10 AMLee Turner
04/17/2024, 8:18 AMVance Jo
04/17/2024, 8:23 AMLee Turner
04/17/2024, 8:25 AM