{"name":"@apideck/better-ajv-errors","version":"0.3.7","keywords":["apideck","ajv","json","schema","json-schema","errors","human"],"author":{"url":"https://apideck.com/","name":"Apideck","email":"support@apideck.com"},"license":"MIT","_id":"@apideck/better-ajv-errors@0.3.7","maintainers":[{"name":"gdewilde","email":"gertjan@apideck.com"},{"name":"nicklloyd","email":"nick@apideck.com"},{"name":"ritiksingh7","email":"ritik@apideck.com"},{"name":"samzani","email":"samir.amzani@gmail.com"},{"name":"lagoni","email":"jonas-lt@live.dk"},{"name":"jakeprins","email":"jake@apideck.com"},{"name":"gmenoiaa","email":"gmenoiaa@gmail.com"}],"contributors":[{"name":"Elias Meire","email":"elias@apideck.com"}],"homepage":"https://github.com/apideck-libraries/better-ajv-errors#readme","bugs":{"url":"https://github.com/apideck-libraries/better-ajv-errors/issues"},"dist":{"shasum":"89238f689d81a644139a47e0ebc2e236bca1ff2c","tarball":"http://registry-npm.ywwl.com/@apideck/better-ajv-errors/download/@apideck/better-ajv-errors-0.3.7.tgz","fileCount":23,"integrity":"sha512-TajUJwGWbDwkCx/CZi7tRE8PVB7simCvKJfHUsSdvps+aTM/PDPP4gkLmKnc+x3CE//y9i/nj74GqdL/hwk7Iw==","signatures":[{"sig":"MEYCIQDBbzgPPS4Hu5mZwg7Ew9cOvoEH/fWKJYA5zpcHMZ+64AIhAOset/fbtb1wKuMYMGpjkyH1UTRMucnq2gsu9CRUsFhE","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":78882,"size":14538,"noattachment":false,"key":"/@apideck/better-ajv-errors/-/@apideck/better-ajv-errors-0.3.7.tgz"},"main":"dist/index.js","husky":{"hooks":{"pre-commit":"tsdx lint"}},"module":"dist/better-ajv-errors.esm.js","engines":{"node":">=10"},"gitHead":"b6327a9021b1e245012d30547ca2b6063d8d555e","scripts":{"lint":"tsdx lint","size":"size-limit","test":"tsdx test","build":"tsdx build","start":"tsdx watch","analyze":"size-limit --why","prepare":"tsdx build","release":"np --no-publish && npm publish --access public --registry https://registry.npmjs.org"},"typings":"dist/index.d.ts","_npmUser":{"name":"gdewilde","email":"gertjan@apideck.com"},"prettier":{"printWidth":120,"singleQuote":true,"trailingComma":"es5"},"repository":{"url":"git+https://github.com/apideck-libraries/better-ajv-errors.git","type":"git"},"size-limit":[{"path":"dist/better-ajv-errors.cjs.production.min.js","limit":"2 KB"},{"path":"dist/better-ajv-errors.esm.js","limit":"2.5 KB"}],"_npmVersion":"10.7.0","description":"Human-friendly JSON Schema validation for APIs","directories":{},"resolutions":{"prettier":"^2.3.0"},"_nodeVersion":"20.15.0","dependencies":{"leven":"^3.1.0","jsonpointer":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"np":"^7.6.1","ajv":"^8.11.0","tsdx":"^0.14.1","husky":"^8.0.1","tslib":"^2.4.0","size-limit":"^7.0.8","typescript":"^4.7.2","json-schema":"^0.4.0","eslint-plugin-prettier":"^4.0.0","@size-limit/preset-small-lib":"^7.0.8"},"peerDependencies":{"ajv":">=8"},"_npmOperationalInternal":{"tmp":"tmp/better-ajv-errors_0.3.7_1774698000384_0.6880887229662445","host":"s3://npm-registry-packages-npm-production"},"readme":"[![npm (scoped)](https://img.shields.io/npm/v/@apideck/better-ajv-errors?color=brightgreen)](https://npmjs.com/@apideck/better-ajv-errors) [![npm](https://img.shields.io/npm/dm/@apideck/better-ajv-errors)](https://npmjs.com/@apideck/better-ajv-errors) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/apideck-libraries/better-ajv-errors/CI)](https://github.com/apideck-libraries/better-ajv-errors/actions/workflows/main.yml?query=branch%3Amain++)\n\n# @apideck/better-ajv-errors 👮‍♀️\n\n> Human-friendly JSON Schema validation for APIs\n\n\n- Readable and helpful [ajv](https://github.com/ajv-validator/ajv) errors\n- API-friendly format\n- Suggestions for spelling mistakes\n- Minimal footprint: 1.56 kB (gzip + minified)\n\n![better-ajv-errors output Example](https://user-images.githubusercontent.com/8850410/118274790-e0529e80-b4c5-11eb-8188-9097c8064c61.png)\n\n## Install\n\n```bash\n$ yarn add @apideck/better-ajv-errors\n```\n\nor\n\n```bash\n$ npm i @apideck/better-ajv-errors\n```\n\nAlso make sure that you've installed [ajv](https://www.npmjs.com/package/ajv) at version 8 or higher.\n\n## Usage\n\nAfter validating some data with ajv, pass the errors to `betterAjvErrors`\n\n```ts\nimport Ajv from 'ajv';\nimport { betterAjvErrors } from '@apideck/better-ajv-errors';\n\n// Without allErrors: true, ajv will only return the first error\nconst ajv = new Ajv({ allErrors: true });\n\nconst valid = ajv.validate(schema, data);\n\nif (!valid) {\n  const betterErrors = betterAjvErrors({ schema, data, errors: ajv.errors });\n}\n```\n\n## API\n\n### betterAjvErrors\n\nFunction that formats ajv validation errors in a human-friendly format.\n\n#### Parameters\n\n- `options: BetterAjvErrorsOptions`\n  - `errors: ErrorObject[] | null | undefined` Your ajv errors, you will find these in the `errors` property of your ajv instance (`ErrorObject` is a type from the ajv package).\n  - `data: Object` The data you passed to ajv to be validated.\n  - `schema: JSONSchema` The schema you passed to ajv to validate against.\n  - `basePath?: string` An optional base path to prefix paths returned by `betterAjvErrors`. For example, in APIs, it could be useful to use `'{requestBody}'` or `'{queryParemeters}'` as a basePath. This will make it clear to users where exactly the error occurred.\n\n#### Return Value\n\n- `ValidationError[]` Array of formatted errors (properties of `ValidationError` below)\n  - `message: string` Formatted error message\n  - `suggestion?: string` Optional suggestion based on provided data and schema\n  - `path: string` Object path where the error occurred (example: `.foo.bar.0.quz`)\n  - `context: { errorType: DefinedError['keyword']; [additionalContext: string]: unknown }` `errorType` is `error.keyword` proxied from `ajv`. `errorType` can be used as a key for i18n if needed. There might be additional properties on context, based on the type of error.\n\n## Related\n\n- [atlassian/better-ajv-errors](https://github.com/atlassian/better-ajv-errors) was the inspiration for this library. Atlassian's library is more focused on CLI errors, this library is focused on developer-friendly API error messages.\n","publish_time":1774698000530,"_cnpm_publish_time":1774698000530,"dist-tags":{"latest":"0.3.7"}}