Hello everyone, i’m having a trouble when i use ajv to validate Json schema. This is my test script:
const expectSchema = {
“definitions”: {
“Welcome”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“id”: {
“type”: “integer”
},
“name”: {
“type”: “string”
},
“type”: {
“type”: “string”
},
“available”: {
“type”: “boolean”
}
},
“required”: [
“available”,
“id”,
“name”,
“type”
],
“title”: “Welcome”
}
}
}
var Ajv = require(‘ajv’)
var ajv = new Ajv({logger: console})
pm.response.json().forEach(function(book){
console.log(ajv.errors)
pm.test(‘Schema is valid’, function() {
pm.expect(ajv.validate(expectSchema, book)).to.be.true;
});
})
And here is examples json when i get them from url:
[
{
“id”: 1,
“name”: “The Russian”,
“type”: “fiction”,
“available”: true
},
{
“id”: 2,
“name”: “Just as I Am”,
“type”: “non-fiction”,
“available”: false
},
{
“id”: 3,
“name”: “The Vanishing Half”,
“type”: “fiction”,
“available”: true
},
{
“id”: 4,
“name”: “The Midnight Library”,
“type”: “fiction”,
“available”: true
},
{
“id”: 5,
“name”: “Untamed”,
“type”: “non-fiction”,
“available”: true
},
{
“id”: 6,
“name”: “Viscount Who Loved Me”,
“type”: “fiction”,
“available”: true
}
]
All my tests are passing when it is run, but when i change type of any properties (example: i change type of id to string or boolean, type of name into integer) my tests still pass. Could you guys explain it to me? thank you sm.