I'm trying to validate my JSON schema and use the additionalProperties: false to confirm there is not other properties. My responseBody look like this:
[
{
"id": 1234567890987654,
"email": "eemail@domain.com",
"civility": 0,
"firstname": "john",
"lastname": "do",
"function": null,
"phone": null,
"cellphone": null,
"role": 1,
"passwordws": "jdnfjnshn55fff5g8"
},
{
...}
]
In the postman tests, I add this
var schema = {
"type": "array",
"properties": {
"id": {"type":"number"},
"email": {"type":"string"},
"civility": {"type":"number"},
"firstname": {"type":"string"},
"lastname": {"type":"string"},
"function": {"type":"string"},
"cellphone": {"type":"string"},
"role": {"type":"number"},
"passwordws": {"type":"string"},
},
"additionalProperties": false,
"required": ["id", "email", "civility", "role", "passwordws"]
};
var data = JSON.parse(responseBody);
var result = tv4.validateResult(data, schema);
tests["Valid schema"] = result.valid;
the test should return FAIL because I deleted the "phone" properties from schema, but test still run valid... I tried to change the schema to {type:array, properties: {type: object, properties {list of properties}additionalProperties: false}} but test still return PASS instead of FAIL... any idea ?