i want to validate following json schema, i am using Ajv npm package.
{
"email": "xyzmail@gmail.com",
"phone": "1112223334",
"country_code": "91"
}
i want either email only, or phone and country_code only, or all of three properties should be there.
i have tried oneOf, allOf, anyOf also have tried nested of theme but in some conditions its working and in some condidions its not working.
i have tried following code
{
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email",
"maxLength": constants.LENGTHS.EMAIL.MAX
},
"phone": {
"type": "string",
"pattern": constants.REGEX.PHONE,
"maxLength": constants.LENGTHS.PHONE.MAX
},
"country_code": {
"type": "string",
"pattern": constants.REGEX.COUNTRY_CODE,
"maxLength": constants.LENGTHS.COUNTRY_CODE.MAX
}
},
"anyOf": [
{
"required": ["email"],
},
{
"required": ["phone", "country_code"],
},
{
"required": ["email", "phone", "country_code"]
},
],
"additionalProperties": false
}