Surya
Surya

Reputation: 149

Karate - Nested JSON object schema validation causes KarateException

Feature: Test Karate schema validation

Scenario: Test nested json objects
 
 * def response = read('tasks.json')
 * def schema = { ab: "##[] string", c: "##[] string" }
 * match response ==
 """
{
      id: '#string',
      name: '#string',
      obj1: '#(schema)' ,
      obj2: '##(schema)' ,
      obj3: '#(schema)' ,
      obj4: '#null' 
      
}
"""

Following is json file used (tasks.json)

{
    "id": "ad:p2:53456:4634:yu",
    "name": "name",
    "obj1": {
        "ab": [
            "test"
        ],
        "c": null
    },
    "obj2": null,
    "obj3": {
        "ab": [
            "tester"
        ],
        "c": [
            "t1", "t2"
        ]
    },
    "obj4": null
}

Error: com.intuit.karate.exception.KarateException: javascript evaluation failed: string, ReferenceError: "string" is not defined in at line number 1

I have tried multiple ways like : obj1: '#(^schema)', obj1: '#object schema'

but not able to fix the issue.

Upvotes: 1

Views: 944

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

It should be ##[] #string , read the docs: https://github.com/intuit/karate#schema-validation

Upvotes: 1

Related Questions