0

I'm trying to use an external reference in Postman and validating that with tv4. This is my code:

  var schema = tv4.getSchema('https://schema.getpostman.com/json/collection/v1/');
  console.log(tv4.validate(responseBody, schema);

and after testing I get

'TypeError Cannot read property '$ref' of undefined'

.

Does that mean my schema is not valid somehow?

John
  • 87
  • 11
  • I get the same error. I know that I am able to get that my schema via an HTTP Get request. Also, when I put it in the JSON.Schema validator, that says it's OK. So not sure how it's failing. – Louis Duran Jun 16 '17 at 23:21

1 Answers1

1

I know it's late, but this could help others

tv4.getSchema(name) is used to retrieve an already loaded schema. tv4.addSchema(name, schema) is used to append a new schema of name with schema value

So, what should you do?

Reading this article I understood that you can't make two requests in a test using Postman. Instead you should store its value in a environment or global variable and don't use tv4's functions as those (I guess) were meant to be used in environments where you can actually download a schema using http module.

Finally, your example should look as this

var schema = JSON.parse(postman.getEnvironmentVariable('myEnvVarName'));
let valid = tv4.validate(pm.response.json(), schema, false, true);
Community
  • 1
  • 1
Alwin Kesler
  • 1,450
  • 1
  • 20
  • 41