Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yup.addMethod(yup.array, 'notEmptyMin', function(min) {
return this.test('notEmptyMin', errorsTrads.min, value => {
if (isEmpty(value)) {
return true;
}
return value.length >= min;
});
});
if (attribute.type === 'dynamiczone') {
let dynamicZoneSchema = yup.array().of(
yup.lazy(({ __component }) => {
return createYupSchema(components[__component], { components });
})
);
const { max, min } = attribute;
if (attribute.required) {
dynamicZoneSchema = dynamicZoneSchema.required();
if (min) {
dynamicZoneSchema = dynamicZoneSchema
.min(min, errorsTrads.min)
.required(errorsTrads.required);
}
} else {
if (min) {
dynamicZoneSchema = dynamicZoneSchema.notEmptyMin(min);
}
}
if (max) {
dynamicZoneSchema = dynamicZoneSchema.max(max, errorsTrads.max);
}
acc[current] = dynamicZoneSchema;
}
return acc;
((!isBoolean(validationValue) &&
Number.isInteger(Math.floor(validationValue))) ||
validationValue === 0)
) {
switch (validation) {
case 'required':
schema = schema.required(errorsTrads.required);
break;
case 'max':
schema = schema.max(validationValue, errorsTrads.max);
break;
case 'maxLength':
schema = schema.max(validationValue, errorsTrads.maxLength);
break;
case 'min':
schema = schema.min(validationValue, errorsTrads.min);
break;
case 'minLength':
schema = schema.min(validationValue, errorsTrads.minLength);
break;
case 'regex':
schema = schema.matches(validationValue, errorsTrads.regex);
break;
case 'lowercase':
if (['text', 'textarea', 'email', 'string'].includes(type)) {
schema = schema.strict().lowercase();
}
break;
case 'uppercase':
if (['text', 'textarea', 'email', 'string'].includes(type)) {
schema = schema.strict().uppercase();
}
});
case 'enumeration':
return yup.object().shape({
name: yup
.string()
.unique(errorsTrads.unique, alreadyTakenAttributes)
.matches(ENUM_REGEX, errorsTrads.regex)
.required(errorsTrads.required),
type: yup.string().required(errorsTrads.required),
default: yup.string().nullable(),
unique: yup.boolean().nullable(),
required: yup.boolean(),
enum: yup
.array()
.of(yup.string())
.min(1, errorsTrads.min)
.hasNotEmptyValues(
'Empty strings are not allowed',
dataToValidate.enum
),
enumName: yup.string().nullable(),
});
case 'number':
case 'integer':
case 'biginteger':
case 'float':
case 'decimal': {
if (dataToValidate.type === 'biginteger') {
return yup.object().shape({
...commonShape,
default: yup
.string()