Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make query parameters in wiremock as optional parameters?

Tags:

wiremock

How can I make query parameter(pageSize) in below json as optional while using wiremock

{
"request": {
    "method": "GET",
    "urlPath": "/claims-search",        
    "queryParameters" : {
        
        "pageSize" : {
            "equalTo" : "10"
        },
        "pageNumber" : {
            "equalTo" : "2"
        }
    }       
},
"response": {
    "status": 200,
    "bodyFileName": "response_200.json",
    "headers": {
      "Content-Type": "application/json"
    }
like image 255
vinay Avatar asked Oct 29 '25 06:10

vinay


1 Answers

If you don't care about what value the query parameters have, you can simply exclude them.

If you need them under certain circumstances, you can use the Or operator to include an absent flag. In your case, it'd look something like...

{ 
    "request": { 
        "method": "GET", 
        "urlPath": "/claims-search",
        "queryParameters" : {
            "pageSize" : {
                "or": [{
                    "equalTo" : "10"
                }, {
                    "absent": true
                }]
            },
            "pageNumber" : {
                "or": [{
                    "equalTo" : "10"
                }, {
                    "absent": true
                }]
            }
        }       
    },
    "response": {
        "status": 200,
        "bodyFileName": "response_200.json",
        "headers": {
          "Content-Type": "application/json"
        }
    }
}

I think this functionality was introduced in WireMock 2.29.0.

like image 94
agoff Avatar answered Oct 31 '25 11:10

agoff