npm (scoped) npm GitHub Workflow Status

@apideck/better-ajv-errors 👮‍♀️

Human-friendly JSON Schema validation for APIs

better-ajv-errors output Example

Install

bash $ yarn add @apideck/better-ajv-errors

or

bash $ npm i @apideck/better-ajv-errors

Also make sure that you’ve installed ajv at version 8 or higher.

Usage

After validating some data with ajv, pass the errors to betterAjvErrors

```ts import Ajv from ‘ajv’; import { betterAjvErrors } from ‘@apideck/better-ajv-errors’;

// Without allErrors: true, ajv will only return the first error const ajv = new Ajv({ allErrors: true });

const valid = ajv.validate(schema, data);

if (!valid) { const betterErrors = betterAjvErrors({ schema, data, errors: ajv.errors }); } ```

API

betterAjvErrors

Function that formats ajv validation errors in a human-friendly format.

Parameters

Return Value

Related