提问者:小点点

Wiremck未模板化请求路径段


我正在尝试使用request. path Segments在响应中呈现一些信息,并且占位符为空…

使用2.26

Wiremck独立启动cmd:

java-jar./wiremck. jar--root-dir"/usr/share/wiremck"--详细--本地响应模板

存根定义:

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

模板位于__files/响应/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}},并且渲染正确。

如果有人能发现我错过了什么…


共1个答案

匿名用户

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


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

我发现这个留档有点模糊,我通常默认为三重,如果三重不起作用,则尝试加倍。我也尽可能避免使用path Segments