简体   繁体   中英

Postman: JSON schema validation always passes even if wrong schema given

I am using Postman and its built-in Json schema validator library (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.

When I use minified JSON in the global variable and then parse it in test script then it works. Don't understand why is that so.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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