本文介绍了空手道API,我该如何匹配2个不同的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据端点的状态,我会从端点收到2个不同的响应,它们之一都可以.

I get 2 different responses from an endpoint depending on it's state and either one of them is fine.

第一反应:

{"available":'#boolean',"collection":'#boolean'}

第二次响应:

{"code": "#string","message": "#string"}

我正在尝试以下操作,但不起作用:

I'm trying the following but it's not working:

  • def firstSchema = {"available":'#boolean',"collection":'#boolean'}
  • def secondSchema = {"code": "#string","message": "#string"}
  • def firstSchema = {"available":'#boolean',"collection":'#boolean'}
  • def secondSchema = {"code": "#string","message": "#string"}

匹配响应包含任何(firstSchema, secondSchema)

有什么想法可以最好地使此工作正常进行,以便任何一种响应都可以吗?

Any ideas how to best get this working so either response is fine?

谢谢

推荐答案

尝试一下:

* def first = { available: true, collection: true }
* def second = { code: 'foo', message: 'bar' }

* def response = second
* def expected = response.code ? { code: '#string', 'message': '#string' } : { available: '#boolean', collection: '#boolean' }
* match response == expected

另请参阅有关条件逻辑"的文档.您可以使用JsonPath来检查"响应的形状,然后定义期望的结果.

Also refer to the documentation on "Conditional Logic". You can use JsonPath to "check" what shape the response is and then define expected results.

这篇关于空手道API,我该如何匹配2个不同的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:05