karatelabs / karate

Test Automation Made Simple

Home Page:https://karatelabs.github.io/karate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schema validation Array issue

TimothyLks opened this issue · comments

I cannot validate schemas that contain arrays, especially if the number of objects is different per request.

Example response:
{
"name": "value",
"id": "value",
"arrayField": []
},
"objects": [
{
"Field1": "value",
"Field2": false,
},
{
"Field1": "value",
"Field2": true,
}
]
}

Bare in mind, that another request may have more objects in the objects array. Also, I do need to check that the Field1 and Field2 are present.

In the feature file, I use the classic:

  • def expectedSchema = read('path to json')
  • match response == expectedSchema

Problem is, I have tried multiple solutions in the schema, but I always get the error:
$ | not equal | actual does not contain key - '#array' (MAP:MAP)
or something similar.

Schema version 1 which will fail if the number of objects is different:

{
"name": "#string",
"id": "#string",
"arrayField": "#array"
},
"objects": [
{
"Field1": "#string",
"Field2": "#boolean",
},
{
"Field1": "#string"",
"Field2": "#boolean",
}
]
}

Schema version 2 which will fail given the above error:
{
"name": "#string",
"id": "#string",
"arrayField": "#array"
},
"objects": "#array"
"#array": [
"Field1": "#string"",
"Field2": "#boolean",
]
}

Is there a way to validate the schema successfully?

@TimothyLks please ask questions like this on stack overflow. for example see: https://stackoverflow.com/search?q=%5Bkarate%5D+schema+array

Apologies