2

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.

Dixie
  • 81
  • 1
  • 1
  • 7
  • 1
    I re-read your question multiple times and have no idea, giving up. try to provide a *simple* example of the validation you are trying to do. – Peter Thomas Jul 26 '19 at 14:42
  • Agreed maybe I was not clear enough, I have now edited the question to make it more clear. Thanks ! – Dixie Jul 26 '19 at 17:52

1 Answers1

3

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)
Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20