{"name":"ajv-errors","version":"3.0.0","description":"Custom error messages in JSON Schemas for Ajv validator","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"rm -rf dist && tsc","eslint":"eslint \"src/**/*.*s\" \"spec/**/*.*s\"","prettier:write":"prettier --write \"./**/*.{json,ts,js}\"","prettier:check":"prettier --list-different \"./**/*.{json,ts,js}\"","test-spec":"jest \"spec/*.ts\"","test-cov":"jest \"spec/*.ts\" --coverage","test":"npm run prettier:check && npm run eslint && npm run build && npm run test-cov","prepublish":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/epoberezkin/ajv-errors.git"},"keywords":["ajv","json-schema","validator","error","messages"],"author":"","license":"MIT","bugs":{"url":"https://github.com/epoberezkin/ajv-errors/issues"},"homepage":"https://github.com/epoberezkin/ajv-errors#readme","peerDependencies":{"ajv":"^8.0.1"},"devDependencies":{"@ajv-validator/config":"^0.3.0","@types/jest":"^26.0.15","@types/node":"^14.14.7","@typescript-eslint/eslint-plugin":"^4.7.0","@typescript-eslint/parser":"^4.7.0","ajv":"^8.0.1","eslint":"^7.2.0","eslint-config-prettier":"^7.0.0","husky":"^5.1.3","jest":"^26.6.3","lint-staged":"^10.5.1","prettier":"^2.1.2","ts-jest":"^26.4.4","typescript":"^4.0.5"},"prettier":"@ajv-validator/config/prettierrc.json","husky":{"hooks":{"pre-commit":"lint-staged && npm test"}},"lint-staged":{"*.{json,yaml,js,ts}":"prettier --write"},"gitHead":"7efe8c29c3ea461eef29335e0199742dbc18e791","_id":"ajv-errors@3.0.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-V3wD15YHfHz6y0KdhYFjyy9vWtEVALT9UrxfN3zqlI6dMioHnJrqOYfyPKol3oqrnCM9uwkcdCwkJ0WUcbLMTQ==","shasum":"e54f299f3a3d30fe144161e5f0d8d51196c527bc","tarball":"http://registry-npm.ywwl.com/ajv-errors/download/ajv-errors-3.0.0.tgz","fileCount":7,"unpackedSize":53233,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgX7iTCRA9TVsSAnZWagAAlUAQAJ/wtbLOi+ebNW6JpzTu\nM7qYiN1gRpk6fBp0jkYngzEqBsDE5dlExsLC5Zldmxk7n8tcS5f95nCPpzD0\ncHrD/SZGLcktBw4BJgtAo7LCZnc2F1zigE5fefBNnsYkFdAZbTryOG6wgAtw\n9tm5drPa9cyprSF7JhfUHea8m34s2MFgizYnjlr/Rvt7zWYvKaHHnxn/1jS9\nCmtt9r4gDDndJsl0gGopHhrOxjJGIED8yZfnuA6uUNeQ7fGvIDTFPcnR7RcM\n5xIntPhbW6waV1Q/BSBLkrLRL8Dz41DrQRlFL5smjFio3aTSLdqLAu6waSSp\n50AL52t1uQZyjXtosJOYv2CBEqm1Gl2EhplV7775acEZDXbgJ+T3iYzaYTAS\nibeyiKMf52AmWPSD+wvAXupsr/R7zK5OwiVg5qCkNOridCTxon8L//CQTuBc\nDnInmT0dJvjRLr04xg0pWR+cGkfcVbUzxmFwxttKFoK/TXLOwi0R/hbvwyWT\nANupN3MkvPs2I3vv7sZFrvftcaEEsJa8Sm4dwOktNskPqD9Ll44uh/ecAzkr\nu4JfhHUxBrioOFHAx3r8Mooyg4p1EAt8TpzYC9i48Qq/EUg8sCY9xlhIfdcq\nknIUzlvULZeOuuRFiMeqEF3Y+D+GrpDPxyYpp7zK3Xjb59GSTsgMAi0gqCvp\nzcLQ\r\n=LoIo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIaK0JaqpfOcA0RijBt/KuDFPZwiCMRBVF24mbaG/znQIhAPYS/UFk2/Wg3lIx4XrM7fMATpzQSdeRUtuP5NQOd94W"}],"size":13054,"noattachment":false,"key":"/ajv-errors/-/ajv-errors-3.0.0.tgz"},"_npmUser":{"name":"esp","email":"e.poberezkin@me.com"},"directories":{},"maintainers":[{"name":"esp","email":"e.poberezkin@me.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ajv-errors_3.0.0_1616885906932_0.28464778966165705"},"_hasShrinkwrap":false,"readme":"# ajv-errors\n\nCustom error messages in JSON-Schema for Ajv validator\n\n[![build](https://github.com/ajv-validator/ajv-errors/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv-errors/actions?query=workflow%3Abuild)\n[![npm](https://img.shields.io/npm/v/ajv-errors.svg)](https://www.npmjs.com/package/ajv-errors)\n[![coverage](https://coveralls.io/repos/github/ajv-validator/ajv-errors/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv-errors?branch=master)\n[![gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)\n\n**Please note**\n\najv-errors v3 supports [ajv v8](https://github.com/ajv-validator/ajv).\n\nIf you are using ajv v6, you should use [ajv-errors v1](https://github.com/ajv-validator/ajv-errors/tree/v1)\n\n## Contents\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Single message](#single-message)\n  - [Messages for keywords](#messages-for-keywords)\n  - [Messages for properties and items](#messages-for-properties-and-items)\n  - [Default message](#default-message)\n- [Templates](#templates)\n- [Options](#options)\n- [Supporters, Enterprise support, Security contact](#supporters)\n- [License](#license)\n\n## Install\n\n```\nnpm install ajv-errors\n```\n\n## Usage\n\nAdd the keyword `errorMessages` to Ajv instance:\n\n```javascript\nconst Ajv = require(\"ajv\").default\nconst ajv = new Ajv({allErrors: true})\n// Ajv option allErrors is required\nrequire(\"ajv-errors\")(ajv /*, {singleError: true} */)\n```\n\nSee [Options](#options) below.\n\n### Single message\n\nReplace all errors in the current schema and subschemas with a single message:\n\n```javascript\nconst schema = {\n  type: \"object\",\n  required: [\"foo\"],\n  properties: {\n    foo: {type: \"integer\"},\n  },\n  additionalProperties: false,\n  errorMessage: \"should be an object with an integer property foo only\",\n}\n\nconst validate = ajv.compile(schema)\nconsole.log(validate({foo: \"a\", bar: 2})) // false\nconsole.log(validate.errors) // processed errors\n```\n\nProcessed errors:\n\n```json5\n[\n  {\n    keyword: \"errorMessage\",\n    message: \"should be an object with an integer property foo only\",\n    // ...\n    params: {\n      errors: [\n        {keyword: \"additionalProperties\", instancePath: \"\" /* , ... */},\n        {keyword: \"type\", instancePath: \".foo\" /* , ... */},\n      ],\n    },\n  },\n]\n```\n\n### Messages for keywords\n\nReplace errors for certain keywords in the current schema only:\n\n```javascript\nconst schema = {\n  type: \"object\",\n  required: [\"foo\"],\n  properties: {\n    foo: {type: \"integer\"},\n  },\n  additionalProperties: false,\n  errorMessage: {\n    type: \"should be an object\", // will not replace internal \"type\" error for the property \"foo\"\n    required: \"should have property foo\",\n    additionalProperties: \"should not have properties other than foo\",\n  },\n}\n\nconst validate = ajv.compile(schema)\nconsole.log(validate({foo: \"a\", bar: 2})) // false\nconsole.log(validate.errors) // processed errors\n```\n\nProcessed errors:\n\n```json5\n[\n  {\n    // original error\n    keyword: type,\n    instancePath: \"/foo\",\n    // ...\n    message: \"should be integer\",\n  },\n  {\n    // generated error\n    keyword: \"errorMessage\",\n    message: \"should not have properties other than foo\",\n    // ...\n    params: {\n      errors: [{keyword: \"additionalProperties\" /* , ... */}],\n    },\n  },\n]\n```\n\nFor keywords \"required\" and \"dependencies\" it is possible to specify different messages for different properties:\n\n```javascript\nconst schema = {\n  type: \"object\",\n  required: [\"foo\", \"bar\"],\n  properties: {\n    foo: {type: \"integer\"},\n    bar: {type: \"string\"},\n  },\n  errorMessage: {\n    type: \"should be an object\", // will not replace internal \"type\" error for the property \"foo\"\n    required: {\n      foo: 'should have an integer property \"foo\"',\n      bar: 'should have a string property \"bar\"',\n    },\n  },\n}\n```\n\n### Messages for properties and items\n\nReplace errors for properties / items (and deeper), regardless where in schema they were created:\n\n```javascript\nconst schema = {\n  type: \"object\",\n  required: [\"foo\", \"bar\"],\n  allOf: [\n    {\n      properties: {\n        foo: {type: \"integer\", minimum: 2},\n        bar: {type: \"string\", minLength: 2},\n      },\n      additionalProperties: false,\n    },\n  ],\n  errorMessage: {\n    properties: {\n      foo: \"data.foo should be integer >= 2\",\n      bar: \"data.bar should be string with length >= 2\",\n    },\n  },\n}\n\nconst validate = ajv.compile(schema)\nconsole.log(validate({foo: 1, bar: \"a\"})) // false\nconsole.log(validate.errors) // processed errors\n```\n\nProcessed errors:\n\n```json5\n[\n  {\n    keyword: \"errorMessage\",\n    message: \"data.foo should be integer >= 2\",\n    instancePath: \"/foo\",\n    // ...\n    params: {\n      errors: [{keyword: \"minimum\" /* , ... */}],\n    },\n  },\n  {\n    keyword: \"errorMessage\",\n    message: \"data.bar should be string with length >= 2\",\n    instancePath: \"/bar\",\n    // ...\n    params: {\n      errors: [{keyword: \"minLength\" /* , ... */}],\n    },\n  },\n]\n```\n\n### Default message\n\nWhen the value of keyword `errorMessage` is an object you can specify a message that will be used if any error appears that is not specified by keywords/properties/items using `_` property:\n\n```javascript\nconst schema = {\n  type: \"object\",\n  required: [\"foo\", \"bar\"],\n  allOf: [\n    {\n      properties: {\n        foo: {type: \"integer\", minimum: 2},\n        bar: {type: \"string\", minLength: 2},\n      },\n      additionalProperties: false,\n    },\n  ],\n  errorMessage: {\n    type: \"data should be an object\",\n    properties: {\n      foo: \"data.foo should be integer >= 2\",\n      bar: \"data.bar should be string with length >= 2\",\n    },\n    _: 'data should have properties \"foo\" and \"bar\" only',\n  },\n}\n\nconst validate = ajv.compile(schema)\nconsole.log(validate({})) // false\nconsole.log(validate.errors) // processed errors\n```\n\nProcessed errors:\n\n```json5\n[\n  {\n    keyword: \"errorMessage\",\n    message: 'data should be an object with properties \"foo\" and \"bar\" only',\n    instancePath: \"\",\n    // ...\n    params: {\n      errors: [{keyword: \"required\" /* , ... */}, {keyword: \"required\" /* , ... */}],\n    },\n  },\n]\n```\n\nThe message in property `_` of `errorMessage` replaces the same errors that would have been replaced if `errorMessage` were a string.\n\n## Templates\n\nCustom error messages used in `errorMessage` keyword can be templates using [JSON-pointers](https://tools.ietf.org/html/rfc6901) or [relative JSON-pointers](http://tools.ietf.org/html/draft-luff-relative-json-pointer-00) to data being validated, in which case the value will be interpolated. Also see [examples](https://gist.github.com/geraintluff/5911303) of relative JSON-pointers.\n\nThe syntax to interpolate a value is `${<pointer>}`.\n\nThe values used in messages will be JSON-stringified:\n\n- to differentiate between `false` and `\"false\"`, etc.\n- to support structured values.\n\nExample:\n\n```javascript\nconst schema = {\n  type: \"object\",\n  properties: {\n    size: {\n      type: \"number\",\n      minimum: 4,\n    },\n  },\n  errorMessage: {\n    properties: {\n      size: \"size should be a number bigger or equal to 4, current value is ${/size}\",\n    },\n  },\n}\n```\n\n#### Using property names in error messages\n\nProperty names can be used in error messages with the relative JSON-pointer (e.g. `0#`). \n\nExample: \n```javascript\nconst schema = {\n  type: \"object\",\n  properties: {\n    size: {\n      type: \"number\",\n    },\n  },\n  additionalProperties: {\n    not: true,\n    errorMessage: “extra property is ${0#}”\n  }\n}\n```\n\n## Options\n\nDefaults:\n\n```json5\n{\n  keepErrors: false,\n  singleError: false,\n}\n```\n\n- _keepErrors_: keep original errors. Default is to remove matched errors (they will still be available in `params.errors` property of generated error). If an error was matched and included in the error generated by `errorMessage` keyword it will have property `emUsed: true`.\n- _singleError_: create one error for all keywords used in `errorMessage` keyword (error messages defined for properties and items are not merged because they have different instancePaths). Multiple error messages are concatenated. Option values:\n  - `false` (default): create multiple errors, one for each message\n  - `true`: create single error, messages are concatenated using `\"; \"`\n  - non-empty string: this string is used as a separator to concatenate messages\n\n## Supporters\n\n[Roger Kepler](https://www.linkedin.com/in/rogerkepler/)\n\n## Enterprise support\n\najv-errors package is a part of [Tidelift enterprise subscription](https://tidelift.com/subscription/pkg/npm-ajv-errors?utm_source=npm-ajv-errors&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.\n\n## Security contact\n\nTo report a security vulnerability, please use the\n[Tidelift security contact](https://tidelift.com/security).\nTidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.\n\n## License\n\n[MIT](https://github.com/epoberezkin/ajv-errors/blob/master/LICENSE)\n","publish_time":1616885907086,"_cnpm_publish_time":1616885907086,"dist-tags":{"beta":"2.0.0-beta.0","latest":"3.0.0"}}