Schema Validation failure

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) –

  1. 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"
                             ]
    
  2. 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

Hi @Anumundada,

Welcome to the community! :clap:

While you have provided quite a bit of information, would you be able to add screenshots as well for more context?

Personally, I read through what you wrote, and while it seems exhaustive, I’m not certain where the issue is.

It looks like you have the right type in your schema for the values. However, in your actual, it looks like you have numbers set to those variables, though, they look like “string” numbers and not actual numbers (or integer types for that matter).

With that, it looks like what you have is correct. Screenshots may help get more information to resolve your issue.

Other than that, it’s been awhile since I have done schema validation, so I can’t immediately see anything wrong with what you’ve provided.

Best,
Orest

Hi All,
I am facing this schema validation error for type Schema is valid | AssertionError: [{“keyword”:“type”,“dataPath”:“[0].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[1].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[2].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[3].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[4].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[5].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[6].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[7].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[8].yield”,“schemaPath”:“#/items/properties/yield/type”,“params”:{“type”:“integer”},“message”:“should be integer”},{“keyword”:“type”,“dataPath”:“[9].close”,“schemaPath”:“#/items/properties/close/type”,“params”:{“type”:“number”},“message”:“should be number”},{“keyword”:“type”,“dataPath”:"
is there any way of ignoring datatypes

my code
var Ajv = require(‘ajv’),
ajv = new Ajv({logger: console , allErrors: true}),
schema = {
// var schema = {
“type”: “array”,
“default”: ,
“title”: “Root Schema”,
“items”: {
“type”: “object”,
“default”: {},
“title”: “A Schema”,
“required”: [
“symbol”,
“name”,
“fund_family”,
“category”,
“asset_class”,
“objective”,
“morningstar_rating”,
“is_index_fund”,
“is_leveraged”,
“close”,
“volume”,
“yield”,
“divexdate”,
// “return1Y”,
“holdings_region”,
“expense_ratio”,
“holdings”
],
“properties”: {
“symbol”: {
“type”: “string”,
“default”: “”,
“title”: “The symbol Schema”,
“examples”: [
“AAA”
]
},
“name”: {
“type”: “string”,
“default”: “”,
“title”: “The name Schema”,
“examples”: [
“AXS First Priority CLO Bond ETF”
]
},

@rituthakur23

I can’t read your code as its all aligned to the left.

Can you please repost using the preformatted text option which will keep the formatting.

Can you also include an example response so we can understand the schema. (Also using the preformatted text option).