我试图使用 Wiremock 独立服务器来实现 POST REST 调用的模拟。我面临这样的挑战,假设帖子正文包含一个“名称”字段及其值,则应该在该 POST 调用的响应中返回相同的值。我的 json 文件如下所示:
{
"priority": 1,
"request": {
"method": "POST",
"urlPath": "/primeSlots",
"bodyPatterns" : [ {
"matchesJsonPath" : "{ \"things\": [ { \"name\": \"794363\" }]
}"
} ]
},
"response": {
"status": 200,
"body": "{{$.things.name.value}}",
"transformers": ["response-template"]
}
}
所以,我需要获取值,即 794363,但使用上述方法无法在响应后正文中获取它。
我也试过这个:
{
"request": {
"method": "POST",
"urlPath": "/transform",
"bodyPatterns": [
{
"matchesJsonPath" : "$.things[?(@.name =~ /[0-9]+/i)]"
}
]
},
"response": {
"status": 200,
"body": "{\"responseName\": \"
{{request.body.things.name.value}}\"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
所以我的问题是,即使我使用与请求中的任何数字匹配的正则表达式,如何使用 Wiremock 独立 json 文件在响应中返回相同的数字?谢谢。