:wave: Hello, team! I hope you are doing well. I a...
# help
d
šŸ‘‹ Hello, team! I hope you are doing well. I am using WireMock Standalone version 3.9.1 and I’m encountering an issue with how query parameters are matched. I have defined two different mapping files for a GET request to /documents with different sets of query parameters, but WireMock is not selecting the correct mapping. Here are the two mappings:
First Mapping (expected match): { "request": { "method": "GET", "urlPath": "/documents", "queryParameters": { "top": { "equalTo": "150" }, "order_by": { "equalTo": "DATE" }, "skip": { "equalTo": "0" }, "order_direction": { "equalTo": "DESC" }, "product_universe": { "equalTo": "SAVINGS_INVESTMENTS" }, "v2": { "equalTo": "true" } } }, "response": { "status": 200, "bodyFileName": "body-api-GET--documents-top-150-order_by-DATE-skip-0-order_direction-DESC-product_universe-SAVINGS_INVESTMENTS-v2-true.json", "headers": { "Content-Type": "application/json; charset=UTF-8" } } }
Second Mapping (unexpected match): { "request": { "method": "GET", "urlPath": "/documents", "queryParameters": { "top": { "equalTo": "150" }, "order_by": { "equalTo": "DATE" }, "order_direction": { "equalTo": "DESC" }, "v2": { "equalTo": "true" } } }, "response": { "status": 200, "bodyFileName": "body-api--documents-top-150-order_by-DATE-order_direction-DESC-v2-true.json", "headers": { "Content-Type": "application/json; charset=UTF-8" } } }
When I make the following request:
GET /documents?top=150&order_by=DATE&skip=0&order_direction=DESC&product_universe=SAVINGS_INVESTMENTS&v2=true
I expect the first mapping to match, but WireMock instead selects the second one. Below is the log output:
Request received: 127.0.0.1 - GET /documents?top=150&order_by=DATE&skip=0&order_direction=DESC&product_universe=SAVINGS_INVESTMENTS&v2=true Matched response definition: { "status": 200, "bodyFileName": "body-api--documents-top-150-order_by-DATE-order_direction-DESC-v2-true.json", "headers": { "Content-Type": "application/json" } } Response: HTTP/1.1 200
Despite the request containing both skip=0 and product_universe=SAVINGS_INVESTMENTS, WireMock matches it to the second mapping, which doesn't include those parameters. I expected WireMock to prioritize the first mapping, as it contains all of the parameters specified in the request. Is there a way to enforce a stricter matching mechanism or a method to ensure that all query parameters are considered in the matching process? Should I be using priority or another mechanism to guarantee that the correct mapping is selected? Thank you in advance for your assistance in resolving this issue.
s
yes, the use of priority will help to make the Wiremock match the first mapping
a better solution would be to use the
absent: true
property in the second mapping for the query params
skip
and
product_universe
āœ… 1
d
thx
s
Welcome