[英]Trying to use external reference in Postman with tv4
I'm trying to use an external reference in Postman and validating that with tv4. 我试图在Postman中使用外部引用,并通过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'
'TypeError无法读取未定义的属性'$ ref''
. 。
Does that mean my schema is not valid somehow? 这是否意味着我的架构无效?
I know it's late, but this could help others 我知道已经晚了,但这可以帮助其他人
tv4.getSchema(name)
is used to retrieve an already loaded schema. tv4.getSchema(name)
用于检索已经加载的架构。 tv4.addSchema(name, schema)
is used to append a new schema of name with schema value tv4.addSchema(name, schema)
用于将具有名称的新模式附加到模式值
Reading this article I understood that you can't make two requests in a test using Postman. 阅读本文后,我了解到您无法在使用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. 相反,您应该将其值存储在环境或全局变量中,并且不要使用tv4的功能,因为(我想)这些功能应在实际可以使用
http
模块下载架构的环境中使用。
Finally, your example should look as this 最后,您的示例应如下所示
var schema = JSON.parse(postman.getEnvironmentVariable('myEnvVarName'));
let valid = tv4.validate(pm.response.json(), schema, false, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.