tv4
tv4 copied to clipboard
How to validate object with set of sub-objects
Hello, I'm writing tests for API validation, and TV4 is very useful for this, but I can't find out how to check this JSon structure :
JSON SOURCE:
{
"count":5,
"version":"1.0",
"19":{
"prestationId":6225,
"luluId":32,
"craftsmanId":null,
"status":"accepted"
},
"20":{
"prestationId":6225,
"luluId":64,
"craftsmanId":null,
"status":"inactive"
},
}
TV4 implementation
var schema = {
"type": "object",
"required": [],
"properties": {
"prestationId": {
"type": "integer"
},
"luluId": {
"type": "integer"
},
"craftsmanId": {
"type": ["integer", "null"]
},
"status": {
"type": { "enum" : [ 'pending', 'accepted', 'refused', 'deleted', 'inactive'] }
},
},
"additionalProperties": false
};
var data = JSON.parse(responseBody);
var result = tv4.validateResult(data, schema);
I just want to watch & validate sub-arrays, not the main one. I've try with $refs but it seems don't work with me.