Karate Nested Schema contains "Not Required" not working?

Viewed 150

i'm trying to understand karat schema fuzsy validation with contains but is not working

if I use ##string for not required it validates required when is null

this is my example

Scenario: Test

* def payload = 
"""
{
    nested: {
        field: 'not required'
    }
}
"""

    * def payload2 = 
"""
{
    nested: null
}
"""

* def schema = 
"""
{
    nested: {
        field: '##string'
    }
}
"""

* match payload contains schema
* match payload2 contains schema

I get this error in console

path: $.nested, actual: null, expected: {field=##string}, reason: actual value is null

Thanks for help

2 Answers

Pay attention to the structure. I think this is what you are trying:

* def part = { field: '#string' }
* def schema = { nested: '##(part)'  }

* def payload = { nested: { field: 'not required' } }
* match payload == schema

* def payload2 = { nested: null }
* match payload2 == schema

And please refer the docs: https://github.com/intuit/karate#schema-validation

yes thanks, also this works

* def schema = 
"""
{
    'nested.field': '##string'
}
"""
Related