{"id":15022290,"url":"https://github.com/up9cloud/chai-json-schema-ajv","last_synced_at":"2025-07-30T08:10:48.477Z","repository":{"id":15614762,"uuid":"78505259","full_name":"up9cloud/chai-json-schema-ajv","owner":"up9cloud","description":"Chai plugin for validate JSON Schema by using ajv.","archived":false,"fork":false,"pushed_at":"2023-01-02T20:21:12.000Z","size":623,"stargazers_count":8,"open_issues_count":9,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T02:19:18.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.chaijs.com/plugins/chai-json-schema-ajv/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/up9cloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-10T06:37:50.000Z","updated_at":"2021-11-04T04:06:31.000Z","dependencies_parsed_at":"2023-01-13T18:30:43.885Z","dependency_job_id":null,"html_url":"https://github.com/up9cloud/chai-json-schema-ajv","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/up9cloud/chai-json-schema-ajv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up9cloud%2Fchai-json-schema-ajv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up9cloud%2Fchai-json-schema-ajv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up9cloud%2Fchai-json-schema-ajv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up9cloud%2Fchai-json-schema-ajv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/up9cloud","download_url":"https://codeload.github.com/up9cloud/chai-json-schema-ajv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up9cloud%2Fchai-json-schema-ajv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267834811,"owners_count":24151642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:57:45.115Z","updated_at":"2025-07-30T08:10:48.390Z","avatar_url":"https://github.com/up9cloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chai-json-schema-ajv\n\n[![Build Status](https://travis-ci.org/up9cloud/chai-json-schema-ajv.svg?branch=master)](https://travis-ci.org/up9cloud/chai-json-schema-ajv)\n[![Coverage Status](https://coveralls.io/repos/github/up9cloud/chai-json-schema-ajv/badge.svg?branch=master)](https://coveralls.io/github/up9cloud/chai-json-schema-ajv?branch=master)\n\nA chai plugin for validate json schema.\n\nThis is based on [ajv](https://github.com/epoberezkin/ajv), a JSON schema Validator.\n\n|version|ajv version|json schema version|\n|---|---|---|\n|[v1](https://github.com/up9cloud/chai-json-schema-ajv/tree/v1)|4.11.8|[JSON Schema draft 4](http://json-schema.org/)|\n|[v2](https://github.com/up9cloud/chai-json-schema-ajv/tree/v2)|5.5.2|[JSON Schema draft-06](https://trac.tools.ietf.org/html/draft-wright-json-schema-validation-01)|\n|[v3](https://github.com/up9cloud/chai-json-schema-ajv/tree/v3)|^6.7.0|[JSON Schema draft-07](http://json-schema.org/latest/json-schema-validation.html)|\n|v4|\u003e=4 \u003c7||\n|v5|\u003e=4 \u003c7|Same as v4, but different message format|\n|v5.2|\u003e=4||\n\n## Installation\n\n```sh\nnpm i ajv --save-dev # Or any version you prefer `npm i ajv@4 --save-dev`\nnpm i chai-json-schema-ajv --save-dev\n```\n\n## Usage\n\n### Validate data (jsonSchema)\n\n```js\nconst chai = require('chai')\nchai.use(require('chai-json-schema-ajv'))\nconst expect = chai.expect\nconst assert = chai.assert\n\nconst apple = {\n  name: 'foo',\n  color: ['red', 'green', 'yellow'],\n  value: 10\n}\nconst car = {\n  name: 'bar',\n  speed: 1.1\n}\nconst schema = {\n  title: 'fruit schema v0.1',\n  type: 'object',\n  required: ['name', 'color', 'value'],\n  properties: {\n    name: {\n      type: 'string',\n      minLength: 3\n    },\n    color: {\n      type: 'array',\n      minItems: 1,\n      uniqueItems: true,\n      items: {\n        type: 'string'\n      }\n    },\n    value: {\n      type: 'integer',\n      minimum: 5\n    }\n  }\n}\n\nexpect(apple).to.be.jsonSchema(schema, 'custom flag')\nexpect(car).to.not.be.jsonSchema(schema, 'custom flag')\n\nassert.jsonSchema(apple, schema, 'custom flag')\nassert.notJsonSchema(car, schema, 'custom flag')\n```\n\n### Validate schema (validJsonSchema)\n\n```js\nconst chai = require('chai')\nchai.use(require('chai-json-schema-ajv'))\nconst expect = chai.expect\nconst assert = chai.assert\n\nconst schema = {\n  title: 'valid schema',\n  type: 'object',\n  required: ['name'],\n  properties: {\n    name: {\n      type: 'string',\n      minLength: 3\n    }\n  }\n}\n\nexpect(schema, 'custom flag').to.be.validJsonSchema\nexpect({ type: '__invalid__' }, 'custom flag').to.not.be.validJsonSchema\n\nassert.validJsonSchema(schema, 'custom flag')\nassert.notValidJsonSchema({ type: '__invalid__' }, 'custom flag')\n```\n\n### Custom options\n\nOptions will also pass to [ajv](https://github.com/epoberezkin/ajv#options)\n\n```js\n...\nconst options = { ... }\nchai.use(\n  require('chai-json-schema-ajv').create(options)\n)\n...\n\n// Basically, it's same as `new Ajv(options)`\n```\n\n#### Option verbose\n\nDefault error message is parsed by `ajv.errorsText`.\n\n```js\n...\nchai.use(\n  require('chai-json-schema-ajv')\n)\n...\n```\n\n```console\nexpected data to match json-schema\ndata should have required property 'color'\n```\n\nIf you go with option `{verbose: true}`, it will print full errors.\n\n```js\n...\nchai.use(\n  require('chai-json-schema-ajv').create({\n    verbose: true\n  })\n)\n...\n```\n\n```console\nexpected { name: 'bar', speed: 1.1 } to match json-schema\n[ { keyword: 'required',\n    dataPath: '',\n    schemaPath: '#/required',\n    params: { missingProperty: 'color' },\n    message: 'should have required property \\'color\\'',\n    schema: \n     { name: { type: 'string', minLength: 3 },\n       color: \n        { type: 'array',\n          minItems: 1,\n          uniqueItems: true,\n          items: { type: 'string' } },\n       value: { type: 'integer', minimum: 5 } },\n    parentSchema: \n     { title: 'fruit schema v0.1',\n       type: 'object',\n       required: [ 'name', 'color', 'value' ],\n       properties: \n        { name: { type: 'string', minLength: 3 },\n          color: \n           { type: 'array',\n             minItems: 1,\n             uniqueItems: true,\n             items: { type: 'string' } },\n          value: { type: 'integer', minimum: 5 } } },\n    data: { name: 'bar', speed: 1.1 } } ]\n```\n\n#### Option ajv\n\nIf you want to reuse ajv instance, you can\n\n```js\nconst ajv = new Ajv\n...\nchai.use(\n  require('chai-json-schema-ajv').create({\n    ajv\n  })\n)\n...\n\nassert.ok(ajv === chai.ajv)\n```\n\n### Access ajv instance\n\n```js\n...\nchai.use(\n  require('chai-json-schema-ajv')\n)\n...\n\nassert.ok(chai.ajv instanceof Ajv)\n```\n\n## TODO\n\n- Support browser side\n- Move to es2017 async/await\n- ~~Add linter~~\n- ~~Send option to ajv~~ (thanks @dimac)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fup9cloud%2Fchai-json-schema-ajv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fup9cloud%2Fchai-json-schema-ajv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fup9cloud%2Fchai-json-schema-ajv/lists"}