Feature: Complex Schema
Background:
* def JSONtobeValidiated =
"""
{
"MyArray": {
"MYinternalDetails": [
{
"SomeField": "dc",
"textfield": [],
"OptionalArray1": [
{
"Users": "Y",
"IsAllowed": "Y"
},
{
"Users": "Y",
"IsAllowed": "Y"
}
]
},
{
"SomeField": "cd",
"textfield": [],
"OptionalArray3": [
{
"Astring": "Lazy",
"AnotherString": "N",
"textfield": []
},
{
"Astring": "FREE",
"AnotherString": "N",
"textfield": [
{
"title": "Name",
"alertMessage": "Please enter valid name."
},
{
"title": "Mobile No",
"alertMessage": "Please enter mobile no."
}
]
}
]
},
{
"SomeField": "gv",
"textfield": [
{
"title": "First",
"alertMessage": "SOme Alert"
}
]
},
{
"SomeField": "rp",
"textfield": []
}
]
}
}"""
* def textfield = { title: '#string', alertMessage: '#string' }
* def OptionalArray1 = { Users: '#string',IsAllowed: '#string' }
* def OptionalArray3 = { Astring: '#string' ,AnotherString: '#string', textfield: '##[]' }
* def MYinternalDetails =
"""
{
SomeField: '#string',
textfield: '##[]',
OptionalArray1: '##[] OptionalArray1'
OptionalArray3: '##[] OptionalArray3'
}
"""
* def ValidJsonSchema = { MyArray: { MYinternalDetails: '#[] MYinternalDetails' } }
Scenario: These matches works
* match JSONtobeValidiated.MyArray.MYinternalDetails == '#[]'
* match JSONtobeValidiated.MyArray.MYinternalDetails == '#[4]'
* match JSONtobeValidiated contains { MyArray: '#ignore' }
* match JSONtobeValidiated contains { MyArray: { MYinternalDetails: '#ignore' } }
Scenario: These match doesn't work
* match JSONtobeValidiated contains { MyArray: { MYinternalDetails: '#[] MYinternalDetails' } }
Scenario: These match doesn't work either
* match JSONtobeValidiated.MyArray.MYinternalDetails == '#[] MYinternalDetails'
Scenario: These match Also doesn't work
* match JSONtobeValidiated == ValidJsonSchema
In Above Example , Schema matching doesn't seems to be working as expected. Need to match full JSON schema.
Reference: https://stackoverflow.com/questions/49231115/karate-complex-json-schema-matching
able to replicate with this example:
Background:
* def json =
"""
{
"foo": {
"bars": [
{ "barOne": "dc", "barTwos": [] },
{ "barOne": "dc", "barTwos": [{ title: 'blah' }] },
{ "barOne": "dc", "barTwos": [{ title: 'blah' }], barThrees: [] },
{ "barOne": "dc", "barTwos": [{ title: 'blah' }], barThrees: [{ num: 1 }] }
]
}
}
"""
* def barTwo = { title: '#string' }
* def barThree = { num: '#number' }
* def bar = { barOne: '#string', barTwos: '#[] barTwo', barThrees: '##[] barThree' }
Scenario:
* match json.foo.bars == '#[] bar'
@avyasbms thanks a lot for finding this, it is fixed in dev. if you can build and run from source, do verify - else we can release a 0.7.0.2 shortly.
Waiting for 0.7.0.2 to verify.
@ptrthomas Can you let me know how to verify?
A lot of our APIs are pending on this one.
@avyasbms sorry, I should have done this earlier, but somehow thought you had a workaround.
I just released 0.7.0.2 - can you confirm that it works ?
Hey @ptrthomas It seems to be working. I'll check more cases and will confirm. Thanks a lot.
Confirming that it worked for many other cases as well. Thanks again!
thanks @avyasbms I'll just keep this open pending the official 0.8.0 release
released 0.8.0