I am getting Assertion error when I run the tv4 or Ajv validators —
AssertionError: [
{“keyword”:“type”,“dataPath”:".SystemVariables[18].Value",“schemaPath”:"#/properties/SystemVariables/items/anyOf/0/properties/Value/type",“params”:{“type”:“string”},“message”:“should be string”},
{“keyword”:“type”,“dataPath”:".SystemVariables[18].DefaultValue",“schemaPath”:"#/properties/SystemVariables/items/anyOf/0/properties/DefaultValue/type",“params”:{“type”:“string”},“message”:“should be string”},
{“keyword”:“anyOf”,“dataPath”:".SystemVariables[18]",“schemaPath”:"#/properties/SystemVariables/items/anyOf",“params”:{},“message”:“should match some schema in anyOf”},
Code for the AJV
var Ajv = require(‘ajv’), ajv = new Ajv({ logger: console, allErrors: true }), schema = {…MASSIVE SCHEMA…}
pm.test(‘Schema is valid from AJV’, function() {
pm.expect(ajv.validate(schema, pm.response.json()), JSON.stringify(ajv.errors)).to.be.true; });
Code for the tv4
var schema_valid = {…massive schema…}
pm.test(“Validate schema”, () => {pm.response.to.have.jsonSchema(schema_valid);});
const responseData = pm.response.json()
pm.test("Schema is valid", function(){
let validation = tv4.validate(responseData, schema_valid);
if (validation !== true) {
console.log(tv4.error);
}
pm.expect(validation).to.be.true;
});
The issue areas mentioned in the Assertion error from the schema(I used a tool to generate schema) –
-
This is the Schema >> Schemepath which is being mentioned in the error–
"Value": { "$id": "#/properties/SystemVariables/items/anyOf/0/properties/Value", "type": "string", "title": "The Value schema", "description": "An explanation about the purpose of this instance.", "default": "", "examples": [ "0" ] }, "DefaultValue": { "$id": "#/properties/SystemVariables/items/anyOf/0/properties/DefaultValue", "type": "string", "title": "The DefaultValue schema", "description": "An explanation about the purpose of this instance.", "default": "", "examples": [ "0" ]
-
This is the datapath from the Schema which is being mentioned in the error
{
“ID”: 18,
“Name”: “HL7A19Timeout”,
“Description”: “Site defined time in seconds that client app waits whilst retrieving demographics”,
“VarType”: “system”,
“Value”: “40”,
“DefaultValue”: “40”
}
CAn some please throw some light as to what is wrong with the schema