Hello, why schema validation doesnt work correctly? if I change in schema properties name to “isd” or any, and response returns with property “id” test pass correctly. Where is the problem?
I have 2 examples of code:
response example:
{
"data": [
{
"id": "string",
"name": "string"
}
],
"total": 0
}
- example :
const jsonData = pm.response.json();
pm.test("schema validation 2", () => {
var Ajv = require('ajv');
ajv = new Ajv(),
s = {
"type": "object",
"data" :{
"type": "array",
"properties":{
"isd": { "type": "string"},
"name": { "name": "string"}
},
"required":["id","name"]
}
};
var validate = ajv.compile(s);
var valid = validate(jsonData);
if(valid === false){
console.log('Invalid: ' + ajv.errorsText(validate.errors));
}
pm.expect(valid).to.be.true;
} );
- example
const schema = {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
]
}
]
},
"total": {
"type": "integer"
}
},
"required": [
"data",
"total"
]
}
pm.test ("Validate schema", () => {
pm.response.to.have.jsonSchema(schema);
})