What is @apideck/better-ajv-errors?
@apideck/better-ajv-errors is a utility package designed to provide more human-readable error messages for JSON schema validation using Ajv. It enhances the default error messages provided by Ajv, making it easier to understand and debug validation issues.
Human-readable error messages
This feature provides more understandable error messages when JSON schema validation fails. The code sample demonstrates how to use @apideck/better-ajv-errors to enhance the error messages from Ajv.
{"const Ajv = require('ajv');":"","const betterAjvErrors = require('@apideck/better-ajv-errors');":"","const ajv = new Ajv();":"","const schema = {":""," type: 'object',":""," properties: {":""," name: { type: 'string' },":""," age: { type: 'integer' }":""," },":""," required: ['name', 'age']":"","};":"","const data = { name: 'John' };":"","const validate = ajv.compile(schema);":"","const valid = validate(data);":"","if (!valid) {":""," const output = betterAjvErrors(schema, data, validate.errors, { format: 'js' });":""," console.log(output);":"","}":""}