我有一个用户列表,一些用户有有关组织的信息,其他用户没有。
如何验证键是对象模式(schemaOrganization)还是空数组?
空手道代码
@表现 功能:API调用示例
Background:
* url url
* def user = call read('../GetToken.feature') { accessToken : response.token }
* def schemaOrganization = { id: '#string', name: '#string'}
* def schemaUser = { id: '#string', name: '#string', organization: '#(schemaOrganization)'}
Scenario: Auth -> api/v1/users
Given path 'api/v1/users'
And header Authorization = 'Bearer '+ user.token
And header Accept-Language = 'en'
When method get
Then status 200
* def data = response.data
* match each data == schemaUser
已经尝试过:
响应待验证
{
"data":[
{
"id":"123-123-123",
"name":"example-name",
"organization":[
]
},
{
"id":"234-234-234",
"name":"example-test",
"organization":{
"id":"org-123",
"name":"example-org"
}
}
]
}
您可以指定
* configure matchEachEmptyAllowed = true
,这将允许它对可选的空列表执行架构验证。
参见:https://github.com/karatelabs/karate/issues/2364#issuecomment-1729668899