JSON Schema validation for Human 👨🎤
Installations
npm install @sidvind/better-ajv-errors
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Min. Node Version
>= 16.14
Node Version
16.20.2
NPM Version
8.19.4
Score
99.3
Supply Chain
100
Quality
77.5
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (98.97%)
TypeScript (0.71%)
Shell (0.32%)
Developer
Download Statistics
Total Downloads
27,400,499
Last Day
64,506
Last Week
271,040
Last Month
1,250,813
Last Year
13,946,059
GitHub Statistics
2 Stars
1,073 Commits
3 Watching
12 Branches
1 Contributors
Bundle Size
34.80 kB
Minified
11.33 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.0.1
Package Id
@sidvind/better-ajv-errors@3.0.1
Unpacked Size
424.75 kB
Size
95.66 kB
File Count
10
NPM Version
8.19.4
Node Version
16.20.2
Publised On
09 Sept 2024
Total Downloads
Cumulative downloads
Total Downloads
27,400,499
Last day
-0.5%
64,506
Compared to previous day
Last week
-14.5%
271,040
Compared to previous week
Last month
4.7%
1,250,813
Compared to previous month
Last year
66.2%
13,946,059
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
JSON Schema validation for Human 👨🎤
Main goal of this library is to provide relevant error messages like the following:
Fork
This fork removes the legacy build and thus drops dependencies such as core-js
and @babel/runtime
which is not needed on modern installations.
- Node 12 and later supports the modern build and according to the release plan node 10 was EOL at 2021-04-30.
- Earlier versions is already EOL and not supported. Anyone using it should update instead.
The following PRs from upstream are merged:
- PR-85: fix: enumeration in anyOf
PR-67: fix(typings): Correct TypeScript type definition(superseeded by upstream fix)PR-70: Drop legacy build and dependecy on polyfills(dropped in favour of esbuild)
The following PRs has been merged upstream:
Installation
1$ npm i @sidvind/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
.
1import Ajv from 'ajv'; 2import betterAjvErrors from '@sidvind/better-ajv-errors'; 3// const Ajv = require('ajv'); 4// const betterAjvErrors = require('@sidvind/better-ajv-errors').default; 5// Or 6// const { default: betterAjvErrors } = require('@sidvid/better-ajv-errors'); 7 8// You need to pass `{ jsonPointers: true }` for older versions of ajv 9const ajv = new Ajv(); 10 11// Load schema and data 12const schema = ...; 13const data = ...; 14 15const validate = ajv.compile(schema); 16const valid = validate(data); 17 18if (!valid) { 19 const output = betterAjvErrors(schema, data, validate.errors); 20 console.log(output); 21}
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:
1[ 2 { 3 start: { line: 6, column: 15, offset: 70 }, 4 end: { line: 6, column: 26, offset: 81 }, 5 error: 6 '/content/0/type should be equal to one of the allowed values: panel, paragraph, ...', 7 suggestion: 'Did you mean paragraph?', 8 }, 9];
indent
Type: number
null
Default: null
If you have an unindented JSON payload and you want the error output indented.
This option have no effect when using the json
option.
json
Type: string
null
Default: null
Raw JSON payload used when formatting codeframe. Gives accurate line and column listings.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (8) are checked with a SAST tool
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/dependabot.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/dependabot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/dependabot.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/dependabot.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/ext/better-ajv-errors/release.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/dependabot.yml:30
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:29
- Info: 0 out of 12 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 2 out of 4 npmCommand dependencies pinned
Reason
dangerous workflow patterns detected
Details
- Warn: script injection with untrusted input ' github.event.pull_request.head.ref ': .github/workflows/dependabot.yml:18
- Warn: script injection with untrusted input ' github.event.pull_request.head.ref ': .github/workflows/dependabot.yml:44
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:17
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:18
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/dependabot.yml:1
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
4.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More