Skip to content

Response Body Does Not Evaluate Multiple Handlebars Templates #1327

@adambricelis

Description

@adambricelis

Describe the bug

When the mapping contains multiple handlebars templates in the response body, the response only includes the evaluation of the first handlebars template.

Expected behavior:

WireMock should evaluate all of the handlebars templates in the mapping and include them in the response.

Test to reproduce

Mapping:

[
  {
    "Request": {
      "Path": "/path0/path1",
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "field": "{{request.PathSegments.[0]}}{{request.PathSegments.[1]}}"
      },
      "UseTransformer": true,
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

Request: GET http://{WIREMOCK_SERVER_HOST}/path0/path1

Expected response:

{
  "field": "path0path1"
}

Actual response:

{
  "field": "path0"
}

Other related info

This issue only occurs when the handlebars template is the prefix of a field in the response body. Adding any characters before the request path segment resolves the issue.

Mapping:

[
  {
    "Request": {
      "Path": "/path0/path1",
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "field": "prefix{{request.PathSegments.[0]}}{{request.PathSegments.[1]}}"
      },
      "UseTransformer": true,
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

Request: GET http://{WIREMOCK_SERVER_HOST}/path0/path1
Response:

{
  "field": "prefixpath0path1"
}

Related issue: #1212

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions