0

I am trying to validate a scheme using tv4 in Postman, but no matter what I do it always passes - even if I force bad data. I am unsure if I am doing something wrong or if there is an issue with tv4 - can anyone help me with this? I am posting the response body and tests below - if you need anything additional let me know:

Response:

{
"categories": [
    {
        "KeyOne": "ValueOne",
        "KeyTwo": "ValueTwo",
        "KeyThree": "ValueThree"
    },
    {
        "KeyOne": "AnotherValueOne",
        "KeyTwo": "AnotherValueTwo",
        "KeyThree": "AnotherValueThree"
    }
]
}

Tests:

var jsonData = pm.response.json();
var categories = JSON.parse(responseBody);
const categoriesSchema = {
  "title": "categories",
  "description": "categories schema",
  "type": "object",
  "categories" : {
  "properties": {
    "KeyOne": {
      "type": "string"
    },
    "KeyTwo": {
      "type": "string"
    },
    "KeyThree": {
    "type": "string"
    }
  },
  "required": [ "KeyOne","KeyTwo","KeyThree" ]
}
};

pm.test('Schema is valid', () => {
  pm.expect(tv4.validate(categories, categoriesSchema)).to.be.true;
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.