How to use ajv-errors - 4 common examples

To help you get started, we’ve selected a few ajv-errors 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 netlify / netlify-cms / packages / netlify-cms-core / src / constants / configSchema.js View on Github external
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);
  }
}
github nick121212 / fx-schema-form / packages / fx-schema-form-react / dts / demo / init.js View on Github external
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")]));
github swagger-api / swagger-editor / src / plugins / json-schema-validator / validator / index.js View on Github external
constructor() {
    this.ajv = new Ajv({
      allErrors: true,
      jsonPointers: true,
    })

    AjvKeywords(this.ajv, "switch")
    AjvErrors(this.ajv)

    this.addSchema(jsonSchema)
  }
github Syncano / syncano-node / packages / lib-js-validate / src / index.js View on Github external
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
  }

ajv-errors

Custom error messages in JSON Schemas for Ajv validator

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis

Popular ajv-errors functions