better-ajv-errors

WebJar for better-ajv-errors

Лицензия

Лицензия

Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

better-ajv-errors
Последняя версия

Последняя версия

0.6.7
Дата

Дата

Тип

Тип

jar
Описание

Описание

better-ajv-errors
WebJar for better-ajv-errors
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/atlassian/better-ajv-errors

Скачать better-ajv-errors

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/better-ajv-errors/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>better-ajv-errors</artifactId>
    <version>0.6.7</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/better-ajv-errors/
implementation 'org.webjars.npm:better-ajv-errors:0.6.7'
// https://jarcasting.com/artifacts/org.webjars.npm/better-ajv-errors/
implementation ("org.webjars.npm:better-ajv-errors:0.6.7")
'org.webjars.npm:better-ajv-errors:jar:0.6.7'
<dependency org="org.webjars.npm" name="better-ajv-errors" rev="0.6.7">
  <artifact name="better-ajv-errors" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='better-ajv-errors', version='0.6.7')
)
libraryDependencies += "org.webjars.npm" % "better-ajv-errors" % "0.6.7"
[org.webjars.npm/better-ajv-errors "0.6.7"]

Зависимости

compile (7)

Идентификатор библиотеки Тип Версия
org.webjars.npm : babel__runtime jar [7.0.0,8)
org.webjars.npm : leven jar [3.1.0,4)
org.webjars.npm : jsonpointer jar [4.0.1,5)
org.webjars.npm : babel__code-frame jar [7.0.0,8)
org.webjars.npm : chalk jar [2.4.1,3)
org.webjars.npm : core-js jar [3.2.1,4)
org.webjars.npm : json-to-ast jar [2.0.3,3)

Модули Проекта

Данный проект не имеет модулей.

better-ajv-errors

JSON Schema validation for Human 👨‍🎤

Main goal of this library is to provide relevant error messages like the following:

Installation

$ yarn add better-ajv-errors
$ # Or
$ npm i better-ajv-errors

Also make sure that you installed ajv package to validate data against JSON schemas.

Usage

First, you need to validate your payload with ajv. If it's invalid then you can pass validate.errors object into better-ajv-errors.

import Ajv from 'ajv';
import betterAjvErrors from 'better-ajv-errors';
// const Ajv = require('ajv');
// const betterAjvErrors = require('better-ajv-errors');

// You need to pass `jsonPointers: true`
const ajv = new Ajv({ jsonPointers: true });

// Load schema and data
const schema = ...;
const data = ...;

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

if (!valid) {
  const output = betterAjvErrors(schema, data, validate.errors);
  console.log(output);
}

API

betterAjvErrors(schema, data, errors, [options])

Returns formatted validation error to print in console. See options.format for further details.

schema

Type: Object

The JSON Schema you used for validation with ajv

data

Type: Object

The JSON payload you validate against using ajv

errors

Type: Array

Array of ajv validation errors

options

Type: Object

format

Type: string
Default: cli
Values: cli js

Use default cli output format if you want to print beautiful validation errors like following:

Or, use js if you are planning to use this with some API. Your output will look like following:

[
  {
    start: { line: 6, column: 15, offset: 70 },
    end: { line: 6, column: 26, offset: 81 },
    error:
      '/content/0/type should be equal to one of the allowed values: panel, paragraph, ...',
    suggestion: 'Did you mean paragraph?',
  },
];
indent

Type: number null
Default: null

If you have an unindented JSON payload and you want the error output indented

org.webjars.npm

Atlassian

Версии библиотеки

Версия
0.6.7
0.5.7