首页 > 解决方案 > 空手道使用模式匹配验证多个可能的值

问题描述

下面是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`

标签: karate

解决方案


可能还有其他方法,但是你去:

* def statuses = ['ACTIVE', 'INACTIVE']
* def schema = { status: '#? statuses.contains(_)' }
* def response = { status: 'ACTIVE' }
* match response == schema

推荐阅读