Complex optional schema validation not working as expected
See original GitHub issueComplex optional schema validation appears works as expected in json. However attempting to do the same in xml does not work as expected.
Feature:
Scenario: JSON
* def subSchema =
"""
{
c: #string
}
"""
* def schema =
"""
{
a: #string,
b: ##(subSchema)
}
"""
* def test1 =
"""
{
a: x,
b: {
c: y
}
}
"""
* match test1 == schema
* def test2 =
"""
{
a: x
}
"""
* match test2 == schema
Scenario: XML
* def subSchema =
"""
<c>#string</c>
"""
* def schema =
"""
<root>
<a>#string</a>
<b>##(subSchema)</b>
</root>
"""
* def test1 =
"""
<root>
<a>x</a>
<b>
<c>y</c>
</b>
</root>
"""
* match test1 == schema
* def test2 =
"""
<root>
<a>x</a>
</root>
"""
* match test2 == schema
In each case b
is a “complex” object which is optional. With json, this field can either be present (and match the expected schema) or not present and the tests will pass. In xml, this does not work. Xml test2 fails with
path: /root, actual: '<root><a>x</a></root>', expected: '<root><a>#string</a><b><c>#string</c></b></root>', reason: all key-values did not match, expected has un-matched keys: [b]
In the xml example, it fails to recognise that b
is optional.
If b
were a “simple” object, then optional handling works as expected e.g. the following will pass
Feature:
Scenario:
* def schema =
"""
<root>
<a>#string</a>
<b>##string</b>
</root>
"""
* def test1 =
"""
<root>
<a>x</a>
<b>y</b>
</root>
"""
* match test1 == schema
* def test2 =
"""
<root>
<a>x</a>
</root>
"""
* match test2 == schema
See the attached example project. This is comprised of the skeleton project (created using Maven quick-start) plus a test.feature file (the top code snippet) which demonstrates the issue. This was tested using karate version 0.9.6 and executed using the command
mvn clean install
myproject.zip
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
@theathlete3141 this is fixed
1.0 released