Reputation: 75
The query I run is going to return a response which I split into two schemas:
* def tagsSchema =
"""
{
"lifecycle-status": "#string",
"infrastructure-environment": "#string",
"managed-by": "#string",
"supported-by": "#string",
"operated-by": "#string"
}
"""
and this schema is integrated into the my content schema:
* def contentSchema =
"""
{
"phase": "##string",
"managedBy": "##string",
"assetId":"##string",
"isValid": ##boolean,
"name": "#string",
"supportedBy": "##string",
"links": '#[] linksSchema',
"ownedBy": "##string",
"cmdbInstanceId":"#string",
"tags": "##object? karate.match(_,tagsSchema).tags",
}
"""
The tagsSchema is optional which I have covered by the ##object. When I run the query now it fails as I do have additional values in tagsSchema.
getList.feature:159 - path: $[0].tags, actual: {"technicalreferant":"email1","billingowner":"xyz","responsibleManager":"email1","environment":"abc","application":"tbd","consumer":"cdr","cr":"12345678"}, expected: '##object? karate.match(_,tagsSchema).tags', reason: did not evaluate to 'true'
The issue is coming from the karate.match but there is no karate.contains. How do I have to modify the schema to avoid this error. The values in the tagsSchema are mandatory while the others can be created by the user at any time and we don't have a policy for them. I don't want to adjust the code every run-time and only rely on mandatory values.
Upvotes: 2
Views: 1233
Reputation: 58088
I'm not sure why you see the need to use karate.match()
and you need to read the documentation. Here's a simple example below:
* def innerSchema = { foo: '#string' }
* def outerSchema = { bar: '#string', baz: '##(innerSchema)' }
* def response1 = { bar: 'x' }
* match response1 == outerSchema
* def response2 = { bar: 'x', baz: { foo: 'y' } }
* match response2 == outerSchema
Upvotes: 2