如何将wiremock中的查询参数设置为可选参数?

How to make query parameters in wiremock as optional parameters?

如何在使用 wiremock

时将下面 json 中的查询参数 (pageSize) 设为可选
{
"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"
    }

如果您不关心查询参数有什么值,您可以简单地排除它们。

如果您在某些情况下需要它们,you can use the Or operator to include an absent flag.在您的情况下,它看起来像...

{ 
    "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"
        }
    }
}

我认为此功能是在 WireMock 2.29.0 中引入的。