ajv json schema validator returns true when the json schema is actually invalid
Notice that dayAdjustment propery must be of type boolean, not string
var Ajv = require('ajv'),
ajv = new Ajv(),
schema = {
"items": {
"type": "object",
"required": [
"id",
"userUpdate",
"dateUpdate",
"timeEntryId",
"approved",
"trcId",
"projectId",
"workOrderId",
"laborId",
"timeIn",
"timeOut",
"adjustmentHours",
"hours",
"totalCost",
"dayAdjustment",
"lastUpdatedBy",
"lastUpdatedDate"
],
"properties": {
"workOrderId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"userUpdate": {
"type": "string"
},
"approved": {
"type": "boolean"
},
"dateUpdate": {
"type": "string"
},
"timeEntryId": {
"type": "integer"
},
"trcId": {
"type": "integer"
},
"projectId": {
"type": "number"
},
"laborId": {
"type": "number"
},
"timeIn": {
"type": "string"
},
"timeOut": {
"type": "string",
},
"adjustmentHours": {
"type": "number"
},
"hours": {
"type": "number",
},
"dayAdjustment": {
"type": "string",
},
"lastUpdatedBy": {
"type": "string"
},
"lastUpdatedDate": {
"type": "string"
},
"totalCost": {
"type": "number"
}
}
}
};
var validate = ajv.compile(schema);
var valid = validate(response);
pm.test('Check that the response is correct', function() {
pm.expect(valid).to.be.true;
});
JSON
{
"id": 81,
"userUpdate": "API_TEST",
"dateUpdate": "20201128043927",
"timeEntryId": 81,
"dateWork": "20201125000000",
"trcId": 1,
"projectId": 458124,
"laborId": 100023699,
"adjustmentHours": 0.0,
"hours": 0.0,
"dayAdjustment": false,
"approved": false,
"lastUpdatedBy": "API_TEST",
"lastUpdatedDate": "20201128043927"
}