Schema validation tv4 return true at all times

Using tv4 to validate schema. The result returns true almost at any time.

Steps to reproduce:

  1. Generate schema here: https://jsonschema.net/
  2. Copy the schema to the local variable.
  3. I did a small change in the schema in object status I changed the attribute type to be an integer, it was string originally.
    The result is: Postman returns true

code:

var schema = pm.variables.get("schema"); 
console.log(schema); 
var JsoneData=JSON.parse(responseBody); 
//var result=tv4.validateResult(JsoneData, schema); 
//console.log(result);

pm.test('Schema is valid', function() { 
    pm.expect(tv4.validate(JsoneData, schema)).to.be.true; 
});

Hey @Kurmavatar,

What’s the response body for this?

I would recommend using Ajv over tv4 within Postman - There have been a few questions around this module recently with some extra information about how it could be used.

2 Likes