我正在使用Wiremock来存根处理移动客户端发出的一些API调用。
努力从请求中获得模板化的文件名。
有人能确认这是否应该甚至与威瑞克独立的工作,请?
"response": { "status": 200, "bodyFileName": "Account-{{jsonPath request.body '$.user.identity'}}.json”}我有静态文件要返回很好,只是似乎bodyFileName不喜欢模板。
示例:
我用以下Json配置wm:
{
"request": {
"method" : "GET",
"url": "/users/D8428899330"
},
"response": {
"status": 200,
"bodyFileName": "user-{{request.path.[1]}}.json"
}
}然后,当我尝试url,http://localhost:9696/users/D8428899330时,我得到以下错误,
HTTP错误: 500问题访问/用户/D 8428899330。原因: /Users/iainframe/Documents/__files/user-{{request.path.1}}.json : java.lang.RuntimeException: java.io.FileNotFoundException(没有这样的文件或目录)
应该表明文件user-D8428899330.json resides在正确的位置,因为我已经对它进行了硬编码,并且它返回了ok。启动WireMock的命令是:
java -jar ~/Documents/wm.jar --port 9696 --global-response-templating --verbose --root-dir /Users/iainframe/Documents/ 发布于 2022-02-03 13:02:34
下面的响应定义在使用响应模板转换器的Wiremock 2.25.1中工作得很好。
"response": {
"transformers": ["response-template"],
"status": 200,
"bodyFileName": "user-{{jsonPath request.body '$.userid'}}.json" }这也很好:
"response": {
"transformers": ["response-template"],
"status": 200,
"bodyFileName": "user-{{request.path.[3]}}.json" }发布于 2022-09-01 18:44:38
有趣的是,我遇到了同样的问题,并且能够通过使用WireMock启动--global-response-templating来解决这个问题。但你也在用那个参数..。如果有关系,我使用的是WireMock 2.33.2。
https://stackoverflow.com/questions/46731203
复制相似问题