I would like to check response from GET/birds request with a json schema. In my feature:
* def abs = read (birds.json)
* match response == abs.birdsSchema
I need to put the schema in a json file and not in the feature. I have to check additional values depending on gender. Ex: if gender is male then check if the color is blue and the tail is long or short. if gender is female then check if "sings" is true or false and number of eggs.
So I put in birds.json:
"birdsSchema":{
"id": "#string",
"owner": "#number",
"town": "#? _ == 'New York' || _ == 'Washington'",
"type": "object",
"oneOf": [
{
"properties": {
"gender": {"enum": ["male"]},
"color":"blue",
"tail": "#? _ == 'long' || _ == 'short'"
}
},
{
"properties": {
"gender": {"enum": ["female"]},
"sings" : "#? _ == true || _ == false"
"eggs": "##number"
}
}
]
}
But it doesn't work. Error: com.intuit.karate.exception.KarateException: path: $[0].type, actual: 'female', expected: 'object', reason: not equal. How I can do this conditional check in my json file?