Gabriel Vilas Boas
10/08/2024, 2:23 AM{
"request": {
"method": "GET",
"urlPattern": "/api/v1/transactions/approval-delegate-rules/.*"
},
"response": {
"transformers": [
"response-transformer"
],
"transformerParameters": {
"url": "/ApprovalDelegateRule?id=eq.{{request.pathSegments.[4]}}"
}
}
}
Could anyone help me on this?Lee Turner
10/08/2024, 6:45 AMGabriel Vilas Boas
10/08/2024, 10:58 AMGabriel Vilas Boas
10/08/2024, 4:10 PMLee Turner
10/08/2024, 4:14 PMGabriel Vilas Boas
10/08/2024, 4:14 PMLee Turner
10/08/2024, 4:16 PMGabriel Vilas Boas
10/08/2024, 4:22 PMGabriel Vilas Boas
10/08/2024, 4:24 PMLee Turner
10/08/2024, 4:26 PMurl
parameter that is null in the parameters when it reaches your transformer ?Gabriel Vilas Boas
10/08/2024, 4:26 PMGabriel Vilas Boas
10/08/2024, 4:27 PMGabriel Vilas Boas
10/08/2024, 4:27 PMLee Turner
10/08/2024, 4:28 PM[]
? - request.pathSegments.4
Gabriel Vilas Boas
10/08/2024, 4:28 PMLee Turner
10/08/2024, 4:30 PMGabriel Vilas Boas
10/08/2024, 4:31 PM"serveEventListeners": [
{
"name": "webhook",
"parameters": {
"method": "GET",
"url": "/ApprovalDelegateRule?id=eq.{{request.pathSegments.[4]}}",
"body": "{ \"result\": \"SUCCESS\" }"
}
},
]
Lee Turner
10/08/2024, 4:32 PMLee Turner
10/08/2024, 4:33 PMGabriel Vilas Boas
10/08/2024, 4:33 PMGabriel Vilas Boas
10/08/2024, 4:33 PMGabriel Vilas Boas
10/08/2024, 4:33 PMLee Turner
10/08/2024, 4:38 PMGabriel Vilas Boas
10/08/2024, 4:39 PMGabriel Vilas Boas
10/08/2024, 4:39 PMGabriel Vilas Boas
10/08/2024, 4:40 PMGabriel Vilas Boas
10/08/2024, 4:41 PMLee Turner
10/08/2024, 4:41 PMLee Turner
10/08/2024, 4:41 PMGabriel Vilas Boas
10/08/2024, 4:44 PMLee Turner
10/08/2024, 4:49 PMGabriel Vilas Boas
10/08/2024, 4:50 PMLee Turner
10/08/2024, 4:57 PMGabriel Vilas Boas
10/08/2024, 4:58 PMGabriel Vilas Boas
10/08/2024, 4:59 PMLee Turner
10/08/2024, 5:02 PMLee Turner
10/08/2024, 5:17 PM@Override
public ResponseDefinition transform(ServeEvent serveEvent) {
TemplateEngine engine = TemplateEngine.defaultTemplateEngine();
final Map<String, Object> model =
new HashMap<>(engine.buildModelForRequest(serveEvent));
Parameters parameters = serveEvent.getTransformerParameters();
String url = parameters.getString("url");
String transformedUrl = engine.getUncachedTemplate(url).apply(model);
return new ResponseDefinitionBuilder()
.withStatus(200)
.withBody(transformedUrl)
.build();
}
I have just written a test inside the wiremock codebase and it does seem to work OK. I passed in a url
parameter of <http://example.com/{{request.id}}>
and the response I got back from the transformer was <http://example.com/a7b5f288-adf9-412f-8474-bb648d48317a>
Lee Turner
10/08/2024, 5:24 PM/api/v1/transactions/approval-delegate-rules/.*
, with this template parameter <http://example.com/{{request.pathSegments.4}}>
and made a request to /api/v1/transactions/approval-delegate-rules/12345
I got back <http://example.com/12345>
Gabriel Vilas Boas
10/08/2024, 5:25 PMGabriel Vilas Boas
10/08/2024, 5:25 PMfinal Map<String, Object> model =
new HashMap<>(engine.buildModelForRequest(serveEvent));
Gabriel Vilas Boas
10/08/2024, 5:26 PMLee Turner
10/08/2024, 5:26 PMGabriel Vilas Boas
10/08/2024, 5:28 PMGabriel Vilas Boas
10/08/2024, 5:28 PMLee Turner
10/08/2024, 5:29 PM