How to use ajv-i18n - 2 common examples

To help you get started, we’ve selected a few ajv-i18n examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github win-winFE / dms / app / assets / components / JsonSchemaForm / validate.js View on Github external
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,
      {
github YMFE / yapi / server / utils / commons.js View on Github external
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
  };
};

ajv-i18n

Internationalised error messages for Ajv JSON validator

MIT
Latest version published 3 years ago

Package Health Score

58 / 100
Full package analysis

Popular ajv-i18n functions