Hi :wave: I'm using the wiremock state extension ...
# wiremock-java
d
Hi 👋 I'm using the wiremock state extension to set the list and then having the response basis the object present in list. But response using handlebars is not as expected. PFA req and resp files in thread
Copy code
{
  "request": {
    "method": "POST",
    "urlPathPattern": "/wiremock/status"
  },
  "response": {
    "status": 200,
    "bodyFileName": "home/statusAccepted.json",
    "headers": {
      "Content-Type": "application/json; charset=utf-8"
    }
  },
  "serveEventListeners": [
    {
      "name": "recordState",
      "parameters": {
        "context": "IdList",
        "list": {
          "addLast": {
            "id": "{{jsonPath request.body '$.id[0]'}}"
          }
        }
      }
    }
  ]
}
Copy code
{
  "request": {
    "method": "GET",
    "urlPathPattern": "/wiremock/status2",
    "customMatcher": {
      "name": "state-matcher",
      "parameters": {
        "hasContext": "IdList",
        "listSizeMoreThan": "0"
      }
    }
  },
  "response": {
    "status": 200,
    "bodyFileName": "home/status2resp.json",
    "headers": {
      "Content-Type": "application/json; charset=utf-8"
    }
  }
}
status2resp.json-
Copy code
{
  "pagination": {
    "pageSize": 1000,
    "totalPages": 1,
    "pageNumber": 1,
    "totalRecords": 1
  },
  "data": [
    {{# each (state context='IdList' property='id' default='[]') }}
    {
      "id": "{{id}}"
    }{{#unless @last}},{{/unless}}
    {{/each}}
  ]
}
I'm getting resp as- { "pagination": { "pageSize": 1000, "totalPages": 1, "pageNumber": 1, "totalRecords": 1 }, "data": [ { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" }, { "id": "" } ] }
any quick help would be appreciated
---------------------------------------- GOT THE SOLUTION just now. use below line in resp file
Copy code
{{# each (state context='IdList' property='list' default='[]') }}
for anyone if it help 🙂
👍 1
d
I will check wether I can place a sensible hint or example in the project.
tq 1