Hi, we are using a WebhookTransformer in some spec...
# help
j
Hi, we are using a WebhookTransformer in some specific cases. Is there a way to apply it only to specific webhooks? We've tried listing it by name in the stubbing (see excerpt below). But I am not sure if this has an effect since it's part of the response and also there's no option to not apply it globally similar to how it is done for ResponseTransformerV2.
Copy code
{
  "response": {
    "transformers": [
      "my-webhook-transformer"
    ]
  }
  "serveEventListeners": {...}
}
l
I think that the
WebhookTransformer
extends the
Extension
interface which means you will need to register your transformer as an extension first. Have you done that already?
j
Yes. And the transformer works as expected on the stubbing I posted above. But it also seems to be applied to every other stubbing that has a
serveEventListeners
configured
The exact use case is that we use transformer parameters and print a warning if they are invalid. If they are for example empty, a developer might just have forgotten to add them or doesn't know how to use the custom transformer properly. This should then be fixed. But we do see false positives because the transformer and it's validation of parameters get's applied to every stub with a
serveEventListener
and not just some specific ones
l
When you say every stub with a
serveEventListener
do you mean any
serveEventListener
or just all webhook serveEventListeners?
j
The latter, we only have webhook serveEventListeners
👍 1
l
From looking at the code it looks like the
WebhookTransformer
get applied to all webhooks. I can't see a way to only apply them to specific webhooks. The
transformers
array only relates to the response transformers from what I can tell
j
Interestingly the parameters from the
transformerParameterss
array are forwarded correctly to our webhook transformer. We can access the value "bar" using the key "foo" with serveEvent.getTransformerParameters() in the implementation of this method with this configuration:
Copy code
{
  "response": {
    "transformers": [
      "my-webhook-transformer"
    ],
    "transformerParameters": {
      "foo": "bar"
    }
  }
  "serveEventListeners": {...}
}
So I guess only the
transformers
array doesn't really do anything for webhook transformers?
l
I don't think so unfortunately.
j
Do you think implementing something similar to how it is done for the ResponseTransformerV2#applyGlobally() is possible/easy?
l
Would need to dig a little deeper in the code and take a look. You could add a new request/enhancement here so we can take a look at it as a team - https://github.com/wiremock/wiremock/issues