Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function oneOfValidator(propertySchema, schemas, getPropertyValidationRules) {
return vuelidate.withParams({
type: 'schemaOneOf',
schemas: schemas,
schema: propertySchema
}, function(val) {
if (!noParamsRequired(val)) {
return true
}
// ignore type errors, the type validator handles that
if (!typeValidator(propertySchema, propertySchema.type)(val)) {
return true
}
return schemas.reduce(function(matching, schema) {
if (matching > 1) return 2
if (validate(getPropertyValidationRules(schema), val)) return matching + 1
module.exports = function allOfValidator(propertySchema, schemas, getPropertyValidationRules) {
return vuelidate.withParams({
type: 'schemaAllOf',
schemas: schemas,
schema: propertySchema
}, function(val) {
if (!noParamsRequired(val)) {
return true
}
// ignore type errors, the type validator handles that
if (!typeValidator(propertySchema, propertySchema.type)(val)) {
return true
}
return schemas.every(function(itemSchema) {
return validate(getPropertyValidationRules(itemSchema), val)
})
module.exports = function notValidator(propertySchema, notSchema, getPropertyValidationRules) {
return vuelidate.withParams({
type: 'schemaNot',
not: notSchema,
schema: propertySchema
}, function(val) {
if (!noParamsRequired(val)) {
return true
}
// ignore type errors, the type validator handles that
if (!typeValidator(propertySchema, propertySchema.type)(val)) {
return true
}
return !validate(getPropertyValidationRules(notSchema), val)
})
}
module.exports = function patternPropertiesValidator(propertySchema, patternProperties, getPropertyValidationRules) {
return vuelidate.withParams({
type: 'schemaPatternProperties',
patternProperties: patternProperties,
schema: propertySchema
}, function(object) {
if (!isPlainObject(object)) return true
if (propertySchema.additionalProperties !== undefined &&
!isPlainObject(propertySchema.additionalProperties) &&
propertySchema.additionalProperties !== true
) {
var allowedKeys = Object.keys(patternProperties).map(function(key) {
return new RegExp(key)
})
var allKeysAreValid = Object.keys(object).every(function(key) {
// we have key, therefore it is valid
module.exports = function minLengthValidator(propertySchema, min) {
return vuelidate.withParams({
type: 'schemaMinLength',
schema: propertySchema,
min: min
}, function(val) {
if (!isString(val)) return true
return val.length >= min
})
}
module.exports = function maxLengthValidator(propertySchema, max) {
return vuelidate.withParams({
type: 'schemaMaxLength',
schema: propertySchema,
max: max
}, function(val) {
if (!isString(val)) return true
return val.length <= max
})
}
module.exports = function oneOfValidator(propertySchema, choices) {
return vuelidate.withParams({
type: 'schemaEnum',
choices: choices,
schema: propertySchema
}, function(val) {
if (!noParamsRequired(val)) return true
return choices.some(function(choice) {
return isEqual(val, choice)
})
})
}
module.exports = function propertyNamesValidator(propertySchema, propertyNames, getPropertyValidationRules) {
return vuelidate.withParams({
type: 'schemaPropertyNames',
propertyNames: propertyNames,
schema: propertySchema
}, function(obj) {
if (!isPlainObject(obj)) return true
var properties = Object.keys(obj)
var validatorGroup = getPropertyValidationRules(propertyNames)
return properties.every(function(property) {
return validate(validatorGroup, property)
})
})
}
module.exports = function additionalPropertiesValidator(propertySchema, additionalProperties, getPropertyValidationRules) {
return vuelidate.withParams({
type: 'schemaAdditionalProperties',
additionalProperties: additionalProperties,
schema: propertySchema
}, function(object) {
if (!object || !isPlainObject(object)) return true
var keys = Object.keys(object)
var properties = Object.keys(propertySchema.properties || {})
var additionalKeys
if (additionalProperties === true || additionalProperties === undefined) {
return true
} else {
if (!propertySchema.patternProperties) {
if (additionalProperties === false) {
return keys.every(function(key) {
return properties.indexOf(key) !== -1
})
module.exports = function requiredValidator(propertySchema, isAttached) {
return vuelidate.withParams({
type: 'schemaRequired',
schema: propertySchema
}, function(val, parent) {
if (!isPlainObject(parent) && isAttached) {
return true
} else {
return noParamsRequired(val)
}
})
}