空手道 API:如何断言 json/response 节点值 returns null 或不同数据的数组对象

Karate API : How to assert a json/response node value which returns null or an array object for different data

我有一个请求 returns 响应节点 (itemCanBe) 的值有两种可能的方式,具体取决于 'itemNum'。我该如何断言?以下尝试无效

* match res..itemCanBe == null || res..itemCanBe[*] contains ['Colgate']

itemCanBe 返回 null

{
"itemDetails": {
    "1234": {
        "itemNum": "1234",
        "itemCanBe": null
    }
  }
}

itemCanBe返回数组

{
"itemDetails": {
    "4567": {
        "itemNum": "4567",
        "itemCanBe": [
            "Colgate",
            "Sensodine"
        ]
    }
}

}

这确实有效:

* def temp = get[0] response..itemCanBe
* match temp == '##[]'

另请参阅:

有关详细信息,请参阅此线程:https://github.com/intuit/karate/issues/1202#issuecomment-653632397 这应该足以解决您的问题。