模式验证:来自特定值列表的字符串 [英] Schema validation: string from specific list of values
本文介绍了模式验证:来自特定值列表的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以下响应的端点:
I have an endpoint with the following response:
{
"id": 1,
"status": "ACTIVE"
}
状态的可能值如下:ACTIVE,INACTIVE,DELETED. 要检查架构,我尝试了以下操作:
The possible values for status are the following: ACTIVE, INACTIVE, DELETED. To check the schema I tried the following:
* def statusValues = ["ACTIVE", "INACTIVE", "DELETED" ]
* def schema =
"""
{
"id" : #number,
"status" : '#(^*statusValues)'
}
"""
为了验证,我使用以下句子:
然后匹配response == schema
And to validate I use the following sentence:
Then match response == schema
但是它不起作用.这是错误
But it doesn't work. This is the error
实际:"ACTIVE",预期:["DELETED","ACTIVE","INACTIVE"],原因: 实际值不像列表一样
actual: 'ACTIVE', expected: ["DELETED","ACTIVE","INACTIVE"], reason: actual value is not list-like
可以帮我吗?
推荐答案
这可能是最简单的选项:
This is probably the simplest option:
* def isValidStatus = function(x){ return statusValues.contains(x) }
* def schema = { id: '#number', status: '#? isValidStatus(_)' }
这篇关于模式验证:来自特定值列表的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文