I am using postman to validate schemas. And the response of an element could be a "number" or "null"
For example:
const schema = {
"type": "object",
"properties": {
"values": {"type": "array",
"items": [
{
"type": "object",
"properties": {
"battery_charge_state": {"type": "number"}
},
"required": [
"battery_charge_state"
]
}
]
},
},
}
pm.test("Schema validation", () => {
pm.response.to.have.jsonSchema(schema);
});
This "battery_charge_state" sometimes could be "null"
How can I validate both scenarios in postman?
Regards
CodePudding user response:
You can do this to handle situation that value can be multiple data types.
"battery_charge_state": {"type": ["number", null]}