Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Array.isArray(additionalMetaSchemas)
) {
ajv = createAjvInstance();
ajv.addMetaSchema(additionalMetaSchemas);
formerMetaSchema = additionalMetaSchemas;
}
let validationError = null;
try {
ajv.validate(schema, formData);
} catch (err) {
validationError = err;
}
// 加入中文错误提示
localize.zh(ajv.errors);
let errors = transformAjvErrors(ajv.errors);
// Clear errors to prevent persistent errors, see #1104
ajv.errors = null;
const noProperMetaSchema =
validationError &&
validationError.message &&
typeof validationError.message === "string" &&
validationError.message.includes("no schema with key or ref ");
if (noProperMetaSchema) {
errors = [
...errors,
{
useDefaults: true,
removeAdditional: flag ? false : true
});
var localize = require('ajv-i18n');
delete schema2.closeRemoveAdditional;
const schema = ejs(schema2);
schema.additionalProperties = flag ? true : false;
const validate = ajv.compile(schema);
let valid = validate(params);
let message = '请求参数 ';
if (!valid) {
localize.zh(validate.errors);
message += ajv.errorsText(validate.errors, { separator: '\n' });
}
return {
valid: valid,
message: message
};
};