Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function validateConfig(config) {
const ajv = new AJV({ allErrors: true, jsonPointers: true });
ajvErrors(ajv);
const valid = ajv.validate(getConfigSchema(), config);
if (!valid) {
console.error('Config Errors', ajv.errors);
throw new ConfigError(ajv.errors);
}
}
array: {
ArrayComponent: ArrayComponent,
ArrayItemComponent: ArrayItemComponent
}
}
});
export const curAjv = new ajv({
allErrors: true,
jsonPointers: true,
useDefaults: true,
format: "full",
$data: true,
errorDataPath: "property",
removeAdditional: true,
});
ajvErrors.default(curAjv, {
keepErrors: false,
singleError: false
});
curAjv.addKeyword("idExists", {
async: true,
type: "string",
validate: checkIdExists
});
function checkIdExists(schema, data) {
console.log("dfjkladjsklfklakdls");
return new Promise((resolve, reject) => {
setTimeout(() => {
if (data === "nick") {
return resolve(true);
}
reject(new ajv.ValidationError([new Error("idExists不是nick")]));
constructor() {
this.ajv = new Ajv({
allErrors: true,
jsonPointers: true,
})
AjvKeywords(this.ajv, "switch")
AjvErrors(this.ajv)
this.addSchema(jsonSchema)
}
static validate (schema, data) {
const ajv = new Ajv({
coerceTypes: true,
$data: true,
allErrors: true,
jsonPointers: true
})
installKeywords(ajv)
installErrors(ajv)
const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) {
const detailsMsg = validate.errors.map(err => {
return ` - ${err.dataPath} - ${err.message} (${JSON.stringify(err.params)})`
}).join('\n')
const error = new Error(`\n\n Validation error:\n${detailsMsg}\n`)
error.details = validate.errors
error.messages = normalise(validate.errors)
throw error
}
return true
}