Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karate Tests: How to match contains each nested array response with just one schema

Tags:

karate

Is possible to match each element of a nested array response (using contains) using just one schema?

I have a set of yml files with request params and response schemas, like this one:

response:
  appId: '#string'
  attributes: '#array'
  login: '#string'
  permissions: '#array'
  metadata:
    roles: '##array'
  userData:
    description: '#string'
    employeeId: '#string'
    employeeNumber: '##string'
    id: '#string'
    login: '#string'
    mail: '#string'
    name: '#string'

and then, in a reusable feature:

* def req = read(<testDataFile>)
* match response contains req.response

I can match nested objects with just one schema but I'm not sure if it's possible use the schema to match nested arrays

maybe like:

response:
  appId: '##string'
  attributes: '##array'
  attributes[*]:
    key: '#string'

or any other expression

Thanks a lot

like image 665
ivangsa Avatar asked Nov 18 '25 09:11

ivangsa


1 Answers

You can't do this with a single "schema" and you have to declare the repeating element separately, as a Karate variable: https://github.com/intuit/karate#schema-validation

* def foo = { a: '#number' }

* def bar = { baz: [{ a: 1 }, { a: 2 }, { a: 3 }] }

* match each bar.baz == foo
* match bar == { baz: '#[] foo' }
like image 98
Peter Thomas Avatar answered Nov 21 '25 10:11

Peter Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!