https://linen.dev logo
#help
Title
# help
h

Hisham Huneidie

10/31/2023, 9:32 AM
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

Lee Turner

10/31/2023, 9:40 AM
Hi, could you let us know what version of wiremock you are using
h

Hisham Huneidie

10/31/2023, 9:41 AM
Yes, the version is
3.2.0
l

Lee Turner

10/31/2023, 9:44 AM
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

Hisham Huneidie

10/31/2023, 9:46 AM
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

Lee Turner

10/31/2023, 9:53 AM
I would try this one:
Copy code
"ten": "{{request.pathSegments.[4]}}"
h

Hisham Huneidie

10/31/2023, 9:54 AM
Perfect, thanks a lot @Lee Turner 🙌
l

Lee Turner

10/31/2023, 9:55 AM
No worries at all
1
t

Tom

10/31/2023, 10:15 PM
{{request.path.videoId}}
should also do the trick
l

Lee Turner

11/01/2023, 9:18 AM
Nice, I haven’t played around with path variables much. That is much better way to reference it
t

Tom

11/01/2023, 9:27 AM
Addressing path variables by name is quite a recent addition. Late in the 3.x beta iirc.
👍 1