Wiremock 没有模板化请求路径段

Wiremock not templating request path segments

我正在尝试使用 request.pathSegments 在响应中呈现一些信息,但该占位符为空...

使用 2.26

Wiremock 独立启动命令:

java -jar ./wiremock.jar --root-dir "/usr/share/wiremock" --verbose --local-response-templating

存根定义:

{
  "mappings": [
    {
      "request": {
        "method": "GET",
        "urlPathPattern": "/v2/path/data/.*"
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "bodyFileName": "responses/data.json",
        "transformers": ["response-template"]
      }
    }
  ]
}

模板位于 __files/responses/data.json:

{
  "data": [
    {
      "id": "{{request.pathSegments.[3]}}",
      "type": "values"
    },
    {
      "id": "{{request.pathSegments.[3]}}",
      "type": "values"
    }
  ]
}

致电http://localhost:8000/v2/path/data/foo

预计:

{
  "data": [
    {
      "id": "foo",
      "type": "values"
    },
    {
      "id": "foo",
      "type": "values"
    }
  ]
}

实际:

{
  "data": [
    {
      "id": "",
      "type": "values"
    },
    {
      "id": "",
      "type": "values"
    }
  ]
}

我试过在模板中使用 {{request.path}} 并且 IS 正确呈现。

如果有人能发现我遗漏的东西...

尝试使用三把手和 path 而不是 pathSegments


  "data": [
    {
      "id": "{{{request.path.[3]}}}",
      "type": "values"
    },
    {
      "id": "{{{request.path.[3]}}}",
      "type": "values"
    }
  ]
}

我发现这方面的文档有些含糊,我通常默认使用三倍,如果三倍不起作用,然后再尝试双倍。我也尽可能避免使用 pathSegments