Karate 如何使用空手道框架检查json模式中是否存在属性值

Karate 如何使用空手道框架检查json模式中是否存在属性值,karate,Karate,我的答复如下: { id: '123', name: 'foo' }` 如果用户没有狗 或 如果用户有狗 在我的专题中,我有: * def schema = { id: '#string', name: '#string', dog: {id: '#string', color: '#string'} }` * match response == schema prb是指如果我有一个没有狗的用户响应,我有以下错误: path: $[0].dog, actual: null, expect

我的答复如下:

 { id: '123', name: 'foo' }` 
如果用户没有狗

如果用户有狗

在我的专题中,我有:

* def schema = { id: '#string', name: '#string', dog: {id: '#string', color: '#string'} }`
* match response == schema
prb是指如果我有一个没有狗的用户响应,我有以下错误:

path: $[0].dog, actual: null, expected: {id=#string, label=#string}, reason: actual value is null
如何检查模式中的属性“dog”?
谢谢

一步不可能做到这一点,另请参阅以下文档:

编辑:这很尴尬,我意识到这个把戏没有很好的记录:

* def dogSchema = { id: '#string', color: '#string' }
* def schema = { id: '#string', name: '#string', dog: "#('##(dogSchema)')" }

* def response1 = { id: '123', name: 'foo' }
* match response1 == schema

* def response2 = { id: '123', name: 'foo', dog: { id: '123', color: 'brown' } }
* match response2 == schema

Edit2:下一个版本将对此进行改进:

谢谢,它可以工作。我将模式放在一个json文件中,并将double###放在这里:
dog:“##('##(dogSchema)')”
。可以验证两种响应。这比Json验证容易得多,而且更好。@nirind在下一个版本中会更容易:
* def dogSchema = { id: '#string', color: '#string' }
* def schema = { id: '#string', name: '#string', dog: '##object' }

* def response1 = { id: '123', name: 'foo' }
* match response1 == schema
* match response1 contains { dog: '##(dogSchema)' }

* def response2 = { id: '123', name: 'foo', dog: { id: '123', color: 'brown' } }
* match response2 == schema
* match response1 contains { dog: '##(dogSchema)' }
* def dogSchema = { id: '#string', color: '#string' }
* def schema = { id: '#string', name: '#string', dog: "#('##(dogSchema)')" }

* def response1 = { id: '123', name: 'foo' }
* match response1 == schema

* def response2 = { id: '123', name: 'foo', dog: { id: '123', color: 'brown' } }
* match response2 == schema