Pick wiremock parameter dynamically

Viewed 46

I am trying to use the body of the request as a lookup object. I can add transformer parameters but then I need to pick the correct one using a json query. For example with this stub:

     stubFor(
        post( "/test" )
          .willReturn(
            aResponse()
              .withBody( "{{ parameters.(jsonPath request.body '$.body')}}" )
              .withTransformerParameter( "data", "newData" ) ) )

Then sending this body: { "body": "data" } would be able to return the string "newData".

The 2 individual parts work: {{jsonPath request.body '$.body'}} returns data and {{ parameters.data }} returns "newData". I cannot find a way to evaluate recursively. When using the above nesting notation, the error is as follows:

could not find helper parameters.

Is there a different notation that would work?

1 Answers

I was able to answer my own question. There is a builtin lookup helper function.

Stubbing with:

       aResponse()
              .withBody( "{{ lookup parameters (jsonPath request.body '$.body')}}" )
              .withTransformerParameter( "data", "newData" ) ) )

Then posting { "body": "data" } returns newData

Related