Reputation: 81
This question came to my mind after asking another question here
Lets say my response is a complex array of JSON object and currently I test like this for complex object.
* def response = [{id: 1}, {id: 2}, {id: 3}.....]
* def schema = { id: "#number" }
* match response == '#[] schema'
I want to replace above match statement with the use of filerKeys() API possibly like as follows
* match response == karate.filterKeys([]schema, response)
Basically first parameter of karate.filterKeys() API should dynamically accept every JSON object from response array and filter against the second parameter response for a successful match.
Upvotes: 2
Views: 717
Reputation: 4239
I think you are trying to dynamically alter your schema for each JSON value in a JSON array.
you can create an equivalent JSON array schema and do a match ==
* def response = [{id: 1},{id: 2}, {id: 3}]
* def schema = { id: '#number' }
* def fun = function(x){ return karate.filterKeys(schema,x) }
* match response == karate.map(response, fun)
Upvotes: 3