Schema validation: string from specific list of values

前提是你 提交于 2019-12-11 06:47:47

问题


I have an endpoint with the following response:

{
     "id": 1,
     "status": "ACTIVE"
   }

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)'
}
"""

And to validate I use the following sentence: Then match response == schema

But it doesn't work. This is the error

actual: 'ACTIVE', expected: ["DELETED","ACTIVE","INACTIVE"], reason: actual value is not list-like

Can you help me, please?


回答1:


This is probably the simplest option:

* def isValidStatus = function(x){ return statusValues.contains(x) }
* def schema = { id: '#number', status: '#? isValidStatus(_)' }


来源:https://stackoverflow.com/questions/57159742/schema-validation-string-from-specific-list-of-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!