简体   繁体   English

邮递员:即使给出了错误的模式,JSON模式验证也始终会通过

[英]Postman: JSON schema validation always passes even if wrong schema given

I am using Postman and its built-in Json schema validator library (tv4). 我正在使用Postman及其内置的Json模式验证器库(tv4)。 There are many earlier posts on the same issue and yet I see that only in some cases issue is resolved. 关于同一问题有很多较早的文章,但是我看到只有在某些情况下问题才能解决。 Here is my Test Script code: 这是我的测试脚本代码:

var data = JSON.parse(responseBody);
console.log("<---data: ", data)
var schema = postman.getGlobalVariable('mySchema')
console.log("<---schema: ", schema)
var result = tv4.validateMultiple(data, schema, false, true);
tests['Schema is valid'] = result['valid'] === true
console.log("<---errors: ", JSON.stringify(result['errors']))

No matter what schema value I pass, the Test always passes. 无论我通过什么schema值,测试都始终通过。

When I use minified JSON in the global variable and then parse it in test script then it works. 当我在全局变量中使用缩小的JSON,然后在测试脚本中对其进行解析时,它将起作用。 Don't understand why is that so. 不明白为什么会这样。

JSON.parse(postman.getGlobalVariable('mySchema'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM