Hello, im using the wire mock standalone jar, how ...
# help
d
Hello, im using the wire mock standalone jar, how can I generate random values in the response body of the mappings?
Example mapping
Copy code
{
  "id": "17210a39-f1d1-4c52-8d9b-6e44e57fa823",
  "name": "actuator_health",
  "request": {
    "url": "/actuator/health",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "body": "{\"randomValue\":\"Number 1 -100\"}",
    "headers": {
      "Vary": [
        "Origin",
        "Access-Control-Request-Method",
        "Access-Control-Request-Headers"
      ],
      "X-Content-Type-Options": "nosniff",
      "X-XSS-Protection": "1; mode=block",
      "Strict-Transport-Security": "max-age=31536000 ; includeSubDomains",
      "X-Frame-Options": "DENY",
      "Content-Type": "application/json;charset=UTF-8",
      "Date": "Thu, 23 Jul 2020 13:02:23 GMT",
      "Server": "web"
    }
  },
  "uuid": "17210a39-f1d1-4c52-8d9b-6e44e57fa823",
  "persistent": true,
  "insertionIndex": 4
}
l
The random values are documented here - https://wiremock.org/docs/response-templating/#random-value-helper Something like this should work:
Copy code
{
  "id": "17210a39-f1d1-4c52-8d9b-6e44e57fa823",
  "name": "actuator_health",
  "request": {
    "url": "/actuator/health",
    "method": "GET"
  },
  "response": {
    "transformers": [
      "response-template"
    ],
    "status": 200,
    "jsonBody": {
      "randomValue": "{{randomValue length=100 type='ALPHANUMERIC_AND_SYMBOLS'}}"
    },
    "headers": {
      "Vary": [
        "Origin",
        "Access-Control-Request-Method",
        "Access-Control-Request-Headers"
      ],
      "X-Content-Type-Options": "nosniff",
      "X-XSS-Protection": "1; mode=block",
      "Strict-Transport-Security": "max-age=31536000 ; includeSubDomains",
      "X-Frame-Options": "DENY",
      "Content-Type": "application/json;charset=UTF-8",
      "Date": "Thu, 23 Jul 2020 13:02:23 GMT",
      "Server": "web"
    }
  },
  "uuid": "17210a39-f1d1-4c52-8d9b-6e44e57fa823",
  "persistent": true,
  "insertionIndex": 4
}
d
Awesome, thank you so much!
@Lee Turner When I try it, it just returns that as a string...
Screenshot 2023-10-05 at 2.29.25 PM.png
l
What version of wiremock are you using ? If you are using the latest version the response templating extension is included but if you are not using the latest you will have to add the extension.
d
2.26.3
l
You will have to add the response templating extension manually with that version. I would definitely upgrade to the latest version if you can though.
d
@Lee Turner Just pulled down the lates and still seeing the same...
wiremock-standalone-3.2.0.jar
Screenshot 2023-10-05 at 2.29.25 PM.png
l
Can you copy your stub mapping here ?
d
Copy code
{
  "id": "17210a39-f1d1-4c52-8d9b-6e44e57fa823",
  "name": "actuator_health",
  "request": {
    "url": "/actuator/health",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "randomValue": "{{randomValue length=100 type='ALPHANUMERIC_AND_SYMBOLS'}}"
    },
    "headers": {
      "Vary": [
        "Origin",
        "Access-Control-Request-Method",
        "Access-Control-Request-Headers"
      ],
      "X-Content-Type-Options": "nosniff",
      "X-XSS-Protection": "1; mode=block",
      "Strict-Transport-Security": "max-age=31536000 ; includeSubDomains",
      "X-Frame-Options": "DENY",
      "Content-Type": "application/json;charset=UTF-8",
      "Date": "Thu, 23 Jul 2020 13:02:23 GMT",
      "Server": "web"
    }
  },
  "uuid": "17210a39-f1d1-4c52-8d9b-6e44e57fa823",
  "persistent": true,
  "insertionIndex": 4
}
l
Sorry, I thought you were using the one I posted above. You need to add the transformers field in the response like the example I posted here - https://wiremock-community.slack.com/archives/C03N1E6HFPY/p1696521080269349?thread_ts=1696517849.764999&channel=C03N1E6HFPY&message_ts=1696521080.269349
d
gotcha, I missed the transformers part, thank you
l
Awesome. Glad it is working.
d
ty Lee!