karate - 空手道使用模式匹配验证多个可能的值
问题描述
下面是schema.json
, 的值city.area.status
可以是 " ACTIVE
" 或 " INACTIVE
",
Schema.json
{
"name": "#string",
"city":{
"area": {
"type": "#string",
"status": "ACTIVE"
}
}
}
我正在使用验证整个架构
* match each Response.hits.hits[*]._source == objectCatSchema
除了city.area.status
字段,不使用#string
,有什么方法可以验证该值是ACTIVE
或者INACTIVE
验证:
* def Response = call read ('`testResponse.json`')
* def expectedSchema = call read ('`citySchema.json`')
* match each `Response.hits.hits[*]._source == objectCatSchema`
解决方案
可能还有其他方法,但是你去:
* def statuses = ['ACTIVE', 'INACTIVE']
* def schema = { status: '#? statuses.contains(_)' }
* def response = { status: 'ACTIVE' }
* match response == schema
推荐阅读
- perl - 如何创建数字标尺和均匀分布的数字宽度标记
- flutter - 本地化使我的底部导航崩溃
- java - 匹配数组模式算法
- flutter - 更改支持的语言环境
- mysql - 数据库(SQL)中的无效默认值(时间戳)问题
- android - BillingClient 和 PurchasesUpdateListener 类不可用
- javascript - Javascript 如何正确获取嵌套对象
- c# - 部署后 ASP.NET Core Web api 未将日志发布到 Seq
- javascript - TypeError:无法读取未定义的属性“access_token”
- javascript - 试图在我的前端显示 MongoDB 文档内容