简体   繁体   English

Wiremock JS 的响应模板有问题

[英]Wiremock JS has problem with response templating

{
    "request": {
        "method": "POST",
        "urlPathPattern": "/v1/customer"
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "bodyFileName": "data/customer-{{jsonPath request.body '$.cid'}}.json",
        "transformers": ["response-template"]
    }
}
  • In Mac, it is working well!在 Mac 中,它运行良好!

  • In Linux, it is giving this error:在 Linux 中,它给出了这个错误:

<pre> Server Error</pre></p><h3>Caused by:</h3>
<pre>java.lang.RuntimeException: java.io.FileNotFoundException:
 /mocks/./__files/data/customer-{{jsonPath request.body &apos;$.cid&apos;}}.json
  (No such file or directory)\n

Is there any solution or workaround?有什么解决方案或解决方法吗? Appreciated!赞赏!

I would advice to always run Wiremock via Docker to prevent issues such as "it works on my machine".我建议始终通过 Docker 运行 Wiremock,以防止诸如“它在我的机器上工作”之类的问题。

However, what works for us on all machines is the following:但是,在所有机器上对我们有用的是以下内容:

{
   "city": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.city'}}",
   "postCode": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.postCode'}}",
   "street1": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.street1'}}",
   "type": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.type'}}",
}

I geuss your OS doesn't like &apos;$.cid&apos;我猜你的操作系统不喜欢&apos;$.cid&apos; . .

And you need to make sure the file exists as well.并且您需要确保该文件也存在。 For me, I always provide a default file to prevent Wiremock from breaking.对我来说,我总是提供一个默认文件来防止 Wiremock 被破坏。 And then use priority to override a specific request.然后使用priority覆盖特定请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM