I defined query parameter in my contract. I need this parameter to be optional:
method 'GET'
url($(regex(urlRegex))) {
queryParameters {
parameter 'fitler': $(stub(regex(filterRegex)))
}
}
I want this contract to be suitable for the both URLs with filter like /my/sample/url?fitler=some-filter-expression
and without the filter param like /my/sample/url
.
How can I achieve this? Is this even possible?
So far, this has no explicit way defined in WireMock spec. However, you have a workaround using regex, by specifying the URL using
urlPathPattern
property (in JSON stubbing). Refer to the example below.Observe the optional portion at the end of the URL, which looks for the typical URL query structure. This, I have tried out in wiremock and it runs smoothly.