Hi, I have a quick question about response templat...
# help
t
Hi, I have a quick question about response templating with random value. Can the same randomly generated value be shared between more than one mapping? If so, what is the recommended way to go about achieving that? Thank you in advance
Copy code
{
  "mappings": [
      {
          "request": {
              "method": "PUT",
              "url": "/some/items"
          },
          "response": {
            "status": 200,
            "jsonBody": {
              "id": "{{randomValue length=34 type='ALPHANUMERIC' uppercase=true}}"
            }
          }
      },
      {
          "request": {
              "method": "GET",
              "url": "/some/items"
          },
          "response": {
              "status": 200,
              "jsonBody": {
                "id": "{{randomValue length=34 type='ALPHANUMERIC' uppercase=true}}".   <------can this be the same id generated by the PUT request
              }
          }
      }
  ]
}
t
There isn’t a way to share data between stubs in this way at the moment except by writing an extension
t
thanks for your response 👍
t
This extension supports what you’re trying to do I think: https://wiremock-community.slack.com/archives/C03NAEH5LVA/p1696835265431819
t
thank you for the follow up. Unaware of this extension, we solved this by doing pre-processing of the mappings before loading them into wiremock. The pre-processor generated the random IDs and inserted them into the mappings where the consistent IDs were needed.
👍 1