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

Todor Avramov

10/05/2023, 1:54 AM
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

Tom

10/05/2023, 3:50 PM
There isn’t a way to share data between stubs in this way at the moment except by writing an extension
t

Todor Avramov

10/08/2023, 4:38 AM
thanks for your response 👍
t

Tom

10/09/2023, 8:31 AM
This extension supports what you’re trying to do I think: https://wiremock-community.slack.com/archives/C03NAEH5LVA/p1696835265431819
t

Todor Avramov

10/09/2023, 4:32 PM
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