const validate = ajv.compile(
{
type: "object",
"properties": {
"name": {
type: "string",
maxLength: 15,
"isNotEmpty": true,
},
"email": { type: "string", format: "email" },
"count": { type: "number", },
"price": { type: "number", },
},
required: ["name"],
"allOf": [
{
"if": {
"properties": { "deliveryType": { const: deliveryTypes.CITY.value } }
},
"then": {
"properties": { "cities": { "type": "array", "minItems": 1, } },
required: ["cities"],
},
},
{
"if": {
"properties": {
"deliveryType": {
"not": {
"const": deliveryTypes.NO_DELIVERY.value
}
}
}
},
"then": {
required: ["country"],
},
},
]
}
);