{"id":15809231,"url":"https://github.com/zordius/api-validator.js","last_synced_at":"2025-03-31T23:44:46.914Z","repository":{"id":21308637,"uuid":"24625122","full_name":"zordius/api-validator.js","owner":"zordius","description":"A nodejs lib and command line tool powered by JSON Schema to validate web API output","archived":false,"fork":false,"pushed_at":"2020-07-15T20:08:09.000Z","size":291,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-06T03:20:19.049Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/api-validator","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zordius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-30T05:02:50.000Z","updated_at":"2019-04-29T02:31:42.000Z","dependencies_parsed_at":"2022-08-20T18:00:28.308Z","dependency_job_id":null,"html_url":"https://github.com/zordius/api-validator.js","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zordius%2Fapi-validator.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zordius%2Fapi-validator.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zordius%2Fapi-validator.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zordius%2Fapi-validator.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zordius","download_url":"https://codeload.github.com/zordius/api-validator.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246558113,"owners_count":20796696,"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","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-10-05T03:20:34.685Z","updated_at":"2025-03-31T23:44:46.892Z","avatar_url":"https://github.com/zordius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"api-validator.js\n================\n\nA nodejs lib and command line tool powered by JSON Schema to validate web API output\n\n[![npm version](https://img.shields.io/npm/v/api-validator.svg)](https://www.npmjs.org/package/api-validator) [![Dependency Status](https://david-dm.org/zordius/api-validator.js.png)](https://david-dm.org/zordius/api-validator.js)  [![Build Status](https://travis-ci.org/zordius/api-validator.js.svg?branch=master)](https://travis-ci.org/zordius/api-validator.js) [![Test Coverage](https://codeclimate.com/github/zordius/api-validator.js/badges/coverage.svg)](https://codeclimate.com/github/zordius/api-validator.js) [![Code Climate](https://codeclimate.com/github/zordius/api-validator.js/badges/gpa.svg)](https://codeclimate.com/github/zordius/api-validator.js) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE.txt)\n\n```sh\n# [You provide] to api-validator.js , (it do):\n[Test Plan] + [API Request Lists] -\u003e (Make Requests) +\n                              [API Response Schemas] + -\u003e (Validation!) = (CI for API!)\n```\n\n```sh\n# In future the whole picture:\n[API Spec] -\u003e (Document generation)\n           -\u003e (Mock API Server)\n           -\u003e (API Request Lists) +\n                      (Test Plan) + -\u003e (Make Requests) +\n           -\u003e                   (API Response Schemas) + -\u003e (Validation!) = (CI for API!)\n```\n\nFeatures\n--------\n\n* JSON Schema V4 Draft Validation (powered by \u003ca href=\"https://github.com/acornejo/jjv\"\u003ejjv\u003c/a\u003e)\n * load schema files\n * handle both remote $ref `http://...` or relative file $ref `file://../.`\n* API Validation - fetch , save , validate , report\n * describe API request and JSON Schema pairs by yaml file\n * make API requests and save response as json files\n * validate on these response\n * output validation results\n * output different test report formats (powered by \u003ca href=\"https://github.com/visionmedia/mocha\"\u003emocha\u003c/a\u003e reports)\n* Command line tool\n * Validate your schema files **TODO**\n * List and fetch referenced remote schema files **TODO**\n * API Validation\n* Customize\n * Authorize requests **TODO**\n * test on \u003ca href=\"https://developer.yahoo.com/yql/\"\u003eYQL tables\u003c/a\u003e\n * test by API blueprint **TODO**\n\nCommand Line Usage\n------------------\n\n**Step 1. Make a plan**\n\n```yaml\n# plan.yaml\nrequestYaml: requests.yaml\nschemaDir: mySchema/path\nprefix: myResults/output/file_\nreportJSON: finalReport/file.json\nrequestConfig:\n  timeout: 500\n```\n\n**Step 2. List requests**\n\n```yaml\n# request.yaml\n- url: http://apihost/endpoint1\n  schema: schema_name1\n- url: http://apihost/endpoint2\n  schema: schema_name2\n- yql: select * from sometable\n  schema: schema_name3\n```\n\n**Step 3. Validate!**\n\n```sh\napi-validator.js plan.yaml \u003e results.json\n```\n\nWill output full context into results.json and exit with 0 when pass.\n\n**Step 4. (optional) Run with Mocha**\n\nRun with mocha then you can using any mocha reporter to see test results. You need to prepare a test.js like this:\n\n```javascript\nrequire('api-validator').mocha('results.json');\n```\n\nThen run mocha:\n\n```shell\nmocha test.js\n```\n\nThe output will be:\n\n```\n  API Validator tests reports by test/yaml/example_yql_plan.yaml\n    ✓ Task \"validatePlan\" should be executed\n    ✓ Task \"loadSchemas\" should be executed\n    ✓ Task \"loadRequestList\" should be executed\n    ✓ Task \"preValidateRequests\" should be executed\n    ✓ Task \"prepareRequest\" should be executed\n    ✓ Task \"validateRequests\" should be executed\n    ✓ Task \"request\" should be executed\n    ✓ Task \"save\" should be executed\n    ✓ Task \"validate\" should be executed\n    ✓ [Saved in file_0001.json] https://query.yahooapis.com/v1/public/yql should pass schema \"https://raw.githubusercontent.com/zordius/api-validator.js/master/schemas/yql.json#/definitions/result\"\n    ✓ [Saved in file_0002.json] https://query.yahooapis.com/v1/public/yql should pass schema \"example://yql.yahoo.com/show_tables\"\n\n\n  11 passing (7ms)\n```\n\nGood JSON Schema practices\n--------------------------\n\n* file name: `*.json` or `*.schema.json`\n* `title` , `id` and `$schema` are required\n* Refer to any resources by correct URI. (GOOD: `\"$ref\": \"http://real.host/real.json#\"` , bad: `\"$ref\": \"any_name\"` )\n* Use `definitions` and `$ref` to decouple schema into many sub schemas\n* Reuse sub schemas\n\nCheck \u003ca href=\"https://github.com/USchema/json\"\u003eboundled schemas\u003c/a\u003e to see examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzordius%2Fapi-validator.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzordius%2Fapi-validator.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzordius%2Fapi-validator.js/lists"}