简体   繁体   English

如果空手道中存在数组 object 属性,如何验证该属性

[英]How to validate Array object attribute if present in Karate

What would be the proper way to create the match string in the case below?在以下情况下创建匹配字符串的正确方法是什么?

I am stuck with the correct match string which would validate both of the below JSON(s).我坚持使用正确的匹配字符串,该字符串将验证以下两个 JSON。

In one of them, we have the "Periods" data,在其中一个中,我们有“时期”数据,

{
    "id": 1,
    "period":
    [
        {
            "startDate": "2022-05-05",
            "endDate": "2022-05-06"
        },
        {
            "startDate": "2022-06-05",
            "endDate": "2022-06-06"
        }
    ]
}

on the other its a null array.另一方面,它是一个 null 阵列。

{
    "id": 1,
    "period": []
}

I have been trying with the below match string but the same seems to fail我一直在尝试使用以下匹配字符串,但似乎同样失败

* match response contains deep "##({period: [{startDate: '#notnull'}]})"

Here you go:这里是 go:

* def dateSchema = { startDate: '#string', endDate: '#string' }
* match response == { id: '#number', period: '#[] dateSchema' }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM