java - 空手道 - 比较多个 JSON 对象架构
问题描述
我正在尝试验证嵌套了多个 JSON 对象的 JSON。例子
Scenario: temp1
* def response1 =
"""
{
"productGroups": [
{
"dateLabel": "28 Aug, Wed",
"products": [
{
"id": 1439,
"product": "product 1"
},
{
"id": 1401,
"product": "product 2"
}
]
}
]
}
"""
* print response1.productGroups
Then match response1.productGroups[*] contains
"""
{
'dateLabel': #string,
'products': [
{
'id': #number,
'product': #string
}
]
}
"""
得到响应为
原因:实际值不包含预期
如果我将验证更改为
Then match response1.productGroups[0] contains
得到响应为
原因:实际和预期的数组大小不同 - 2:1
我想做的是验证“productGroups”对象的模式以及“产品”的内部对象
解决方案
请花一些时间阅读文档,这是值得的:https ://github.com/intuit/karate#schema-validation
* def product = { 'id': #number, 'product': #string }
Then match response1.productGroups[*] contains
"""
{
'dateLabel': #string,
'products': '#[] product'
}
"""
推荐阅读
- c++ - CPD 点云注册 (CPD-Library) 与点云库 (C++) 结合使用
- r - 'lib = "C:/Users/xxx/Documents/R/win-library/4.0"' 不可写
- matplotlib - 使用 matplotlib 绘制固定长度的线段(切线)以保留纵横角
- android - Mockito 说使用 MutableLiveData 值时实际调用有不同的参数
- sql - 选择 id = 0 或 id = 555 但不能同时选择两者 - ORACLE SQL
- azure - 具有存储帐户专用终结点的 Azure CDN
- python - JSon -Parse with Python中的多行逗号分隔列表
- r - R数据框:根据某些列删除重复项
- mysql - 何时用数据库结构中的另一个表替换表列相关?
- sql - MySQL 到 PostgreSQL - 在数组中查找并计算数组值