Newman tv4 schema validation does not work

@rjayaram I saw that the response body doesn’t have the QIS property, that’s at least what the error was thrown.

For eg (one of the errors):
At the beginning of the response, it says that sparkTemplates has the required property QIS missing.
So, I added a random QIS property to the sparkTemplates object and then the error went away. But yes, there are more validation errors that came after that.
image

You can update your script like so to debug even better:

pm.test("Test 18: Response body is valid", function () {
   data = resp;

   var schema_response = JSON.parse(globals['search_response_schema']);
   console.log({ schema_response });
   
   // More detailed error, so that you can see where the validation fails
   tv4.setErrorReporter(function (error, data, schema) {
    return { e: "Error: " + error.code, data };
   });

   //Reference: https://stackoverflow.com/questions/48098530/how-do-i-test-json
   valid = tv4.validate(data, schema_response, true, true);

   console.log({ valid });
   console.log("Validation errors: ", tv4.error);
   if (valid !== true) {
     console.log(tv4.error);
   }

   pm.expect(valid).to.be.true;
});

Also, you can open the DevTools for an easier view of the console logs, also with the modified script that I wrote above that gives more detailed error message, you can check that where exactly the validation is failing (on which piece of data).
You can click on View > Developer > Show DevTools (Current View)

It shows that the response has some issues / the schema has some issues.
If you think there’s no issue there, then it looks like an issue with the tv4 library itself.

You can locally setup a node project and verify with tv4, whether it’s actually working or not.
tv4 repo: GitHub - geraintluff/tv4: Tiny Validator for JSON Schema v4