I am trying to use the request.pathSegments
to render some information in a response and that placeholder is empty...
using 2.26
Wiremock standalone start up cmd:
java -jar ./wiremock.jar --root-dir "/usr/share/wiremock" --verbose --local-response-templating
Stub definition:
{
"mappings": [
{
"request": {
"method": "GET",
"urlPathPattern": "/v2/path/data/.*"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "responses/data.json",
"transformers": ["response-template"]
}
}
]
}
template located in __files/responses/data.json:
{
"data": [
{
"id": "{{request.pathSegments.[3]}}",
"type": "values"
},
{
"id": "{{request.pathSegments.[3]}}",
"type": "values"
}
]
}
call to http://localhost:8000/v2/path/data/foo
expected:
{
"data": [
{
"id": "foo",
"type": "values"
},
{
"id": "foo",
"type": "values"
}
]
}
actual:
{
"data": [
{
"id": "",
"type": "values"
},
{
"id": "",
"type": "values"
}
]
}
I have tried using {{request.path}}
in teh template and that IS rendered correctly.
If anyone can spot what I'm missing...
Try using triple handlebars and
path
instead ofpathSegments
.I find the documentation on this somewhat vague, and I usually default to triple, and then try double if the triple doesn't work. I also avoid using
pathSegments
when possible.