Hello guys. Tiny question. I was reading the docs ...
# help
h
Hello guys. Tiny question. I was reading the docs but the mentioned solution does work for me. I have this mapping file
Copy code
// mappings/MediaGallery/get-video-mapping.json
{
    "request": {
        "method": "GET",
        "urlPathTemplate": "/wiremock/media/library/video/{videoId}"
    },
    "response": {
        "status": 200,
        "bodyFileName": "MediaGallery/media-video-with-id.json",
        "headers": {
            "Content-Type": "application/json"
        }
    }
}
And a body response file
Copy code
// __files/MediaGallery/media-video-with-id.json
{
    "one":  ${videoId},
    "two":  "${videoId}",
    "three":  {videoId},
    "four":  {{videoId}},
    "five":  "{videoId}",
    "six":  "{{videoId}}",
    "seven":  $.videoId,
    "eight":  {$.videoId},
    "nine":  ${$.videoId},
    "ten":  {{request.pathSegments.[1]}},
}
The variable doesn’t get replaced. No one of these combinations work. ¿What is the form to write a variable in my body response file? Thanks
l
Hi, could you let us know what version of wiremock you are using
h
Yes, the version is
3.2.0
l
Could you try adding the response template transformer:
Copy code
"transformers" : [ "response-template" ]
Copy code
{
  "request": {
    "method": "GET",
    "urlPathTemplate": "/wiremock/media/library/video/{videoId}"
  },
  "response": {
    "status": 200,
    "bodyFileName": "media-video-with-id.json",
    "headers": {
      "Content-Type": "application/json"
    },
    "transformers": [
      "response-template"
    ]
  }
}
h
Ok, and ¿what should be the correct form to call my variable?
Copy code
{
    "one":  ${videoId},
    "two":  "${videoId}",
    "three":  {videoId},
    "four":  {{videoId}},
    "five":  "{videoId}",
    "six":  "{{videoId}}",
    "seven":  $.videoId,
    "eight":  {$.videoId},
    "nine":  ${$.videoId},
    "ten":  {{request.pathSegments.[1]}},
}
l
I would try this one:
Copy code
"ten": "{{request.pathSegments.[4]}}"
h
Perfect, thanks a lot @Lee Turner 🙌
l
No worries at all
1
t
{{request.path.videoId}}
should also do the trick
l
Nice, I haven’t played around with path variables much. That is much better way to reference it
t
Addressing path variables by name is quite a recent addition. Late in the 3.x beta iirc.
👍 1
h
@Tom I have just tried your option and it works perfectly. Thanks a lot, sorry for the delay (I didn’t read your message)
👍 1