karate - all key-values did not match for jsonschema
问题描述
I have jsonschema like this below :
{
"id": 0,
"rc": "51",
"product": {
"code": "28",
"label": "PLN",
"type": "electricity",
"ops": "PLN",
"nominal": 50000
},
"cust_id": "01428800200",
"order_id": "",
"ref_no": "2033930693200733",
"amount": 50000,
"price": 50000,
"created": -62135596800
}
and this is my schema validation
{
"id": "#number",
"rc": "#string",
"product": {
"code": "#string",
"label": "#string",
"type": "#string",
"ops": "#string",
"nominal": "#number"
},
"cust_id": "#string",
"order_id": "#string",
"ref_no": "#string",
"amount": "#number",
"price": "#number",
"created": "#number? _ < 0"
}
but I get message reason: all key-values did not match
, but I think that my schema is correct, so does anyone can help me with this ??
解决方案
这对我有用,你的脚本中一定有一些错误。将以下内容粘贴到一个新的功能文件中,看看它是否适合您自己:
* def response =
"""
{
"id": 0,
"rc": "51",
"product": {
"code": "28",
"label": "PLN",
"type": "electricity",
"ops": "PLN",
"nominal": 50000
},
"cust_id": "01428800200",
"order_id": "",
"ref_no": "2033930693200733",
"amount": 50000,
"price": 50000,
"created": -62135596800
}
"""
* def schema =
"""
{
"id": "#number",
"rc": "#string",
"product": {
"code": "#string",
"label": "#string",
"type": "#string",
"ops": "#string",
"nominal": "#number"
},
"cust_id": "#string",
"order_id": "#string",
"ref_no": "#string",
"amount": "#number",
"price": "#number",
"created": "#number? _ < 0"
}
"""
* match response == schema
推荐阅读
- python - 如何在选定的子列表索引处提取、访问和使用列表的所有值?
- typescript - 如果未包含在当前项目中,则忽略引用 typescript 库的类型
- ios - 是否可以在 dart/flutter 项目的编译时获取当前时间?
- java - onClickListeners 之间的变量重置为默认值
- python - 是否可以使用“LIKE”和 SqlAlchemy 在 JSONB 列表中搜索值?
- php - 带if语句的php代码说明
- python - Pytorch 和 numpy 广播规则的区别?
- regex - 如果输入的前 3 个字符的值为“xyz”,如何禁用提交按钮并显示 div
- c# - 如何在 ListView 中的 ViewCell 中添加 Material Design 波纹效果?
- powershell - 如何从 Get-ADUser 以相同格式捕获和保存数据,但具有属性子集?