I have the following schema which makes use of the dependentRequired statement:
const schema2 = {
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" },
"billing_address": { "type": "string" }
},
"required": ["name"],
"dependentRequired": {
"credit_card": ["billing_address"]
}
}
pm.test("Validate dependentRequired Schema", ()=>{
pm.response.to.have.jsonSchema(schema2);
})
The validation is expected to fail for the following scenario where the billing address is missing. This is also working fine when I test it with https://www.jsonschemavalidator.net/ but in Postman, the Test Result is always passing.
{
"name": "John Doe",
"credit_card": 5555555555555555
}
The only way that this works as expected is when I add the “required” statement after dependentRequired i.e.
const schema2 = {
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" },
"billing_address": { "type": "string" }
},
"required": ["name"],
"dependentRequired": {
"credit_card": ["billing_address"]
},
"required": ["billing_address"]
}
But, doesn’t this defeat the purpose of using “dependentRequired”?