我可以回复:
{ id: '123', name: 'foo' }`
如果用户没有狗
OR
{ id: '123', name: 'foo', dog: {id: '123', color: 'brown'} }`
如果用户有狗。
在我的专辑中,我有:
* 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'在我的架构? 感谢
答案 0 :(得分:1)
无法一步完成此操作,另请参阅schema validation上的文档:
* 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
Edit2:这将在下一版本中得到改进:https://github.com/intuit/karate/issues/248