diff --git a/package-lock.json b/package-lock.json index 60a4c17..3c0be57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0-development", "license": "Apache-2.0", "dependencies": { + "@json-schema-tools/validator": "^1.4.0", "@open-rpc/schema-utils-js": "^1.14.0", "@types/isomorphic-fetch": "0.0.35", "@types/lodash": "^4.14.162", @@ -1534,9 +1535,18 @@ } }, "node_modules/@json-schema-tools/traverse": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/@json-schema-tools/traverse/-/traverse-1.7.7.tgz", - "integrity": "sha512-ch/pPoOEIeKe1PKbfuLEIM8MAdTiR+fr9BYk6VTlIHrya5f5d8shJg6h/oQgD3K/ftjU/RYBGGalw9Pz4pCXew==" + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@json-schema-tools/traverse/-/traverse-1.10.3.tgz", + "integrity": "sha512-1F8m574UObc3HuJoGGdmiOe2Ft9ObVypEKoniREs5v2G03wF/nb3YRTYFjKmI0z4S5NkdJwPFRwo7MjTjkI7Qg==" + }, + "node_modules/@json-schema-tools/validator": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@json-schema-tools/validator/-/validator-1.4.0.tgz", + "integrity": "sha512-0t/dBRszJEznq96EBabltiogsWxY/O2ECa9oM85a2By6q2uARJeztymdM9gmPFi0AhxlpOIi/byZcR+4zSvIMw==", + "dependencies": { + "@json-schema-tools/traverse": "^1.10.0", + "jsonpath": "^1.1.1" + } }, "node_modules/@open-rpc/meta-schema": { "version": "1.14.0", @@ -2663,8 +2673,7 @@ "node_modules/deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", - "dev": true + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=" }, "node_modules/deepmerge": { "version": "4.2.2", @@ -2826,7 +2835,6 @@ "version": "1.14.1", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.14.1.tgz", "integrity": "sha512-Bmt7NcRySdIfNPfU2ZoXDrrXsG9ZjvDxcAlMfDUgRBjLOWTuIACXPBFJH7Z+cLb40JeQco5toikyc9t9P8E9SQ==", - "dev": true, "dependencies": { "esprima": "^4.0.1", "estraverse": "^4.2.0", @@ -2860,7 +2868,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, "engines": { "node": ">=4.0" } @@ -2869,7 +2876,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -3200,8 +3206,7 @@ "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", - "dev": true + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, "node_modules/fast-safe-stringify": { "version": "2.0.7", @@ -6809,6 +6814,16 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsonpath": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/jsonpath/-/jsonpath-1.1.1.tgz", + "integrity": "sha512-l6Cg7jRpixfbgoWgkrl77dgEj8RPvND0wMH6TwQmi9Qs4TFfS9u5cUFnbeKTwj5ga5Y3BTGGNI28k117LJ009w==", + "dependencies": { + "esprima": "1.2.2", + "static-eval": "2.0.2", + "underscore": "1.12.1" + } + }, "node_modules/jsonpath-plus": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-5.1.0.tgz", @@ -6817,6 +6832,18 @@ "node": ">=10.0.0" } }, + "node_modules/jsonpath/node_modules/esprima": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.2.2.tgz", + "integrity": "sha512-+JpPZam9w5DuJ3Q67SqsMGtiHKENSMRVoxvArfJZK01/BfLEObtZ6orJa/MtoGNR/rfMgp5837T41PAmTwAv/A==", + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -6863,7 +6890,6 @@ "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", - "dev": true, "dependencies": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" @@ -7323,7 +7349,6 @@ "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", - "dev": true, "dependencies": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.6", @@ -7514,7 +7539,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", - "dev": true, "engines": { "node": ">= 0.8.0" } @@ -8357,7 +8381,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, + "devOptional": true, "engines": { "node": ">=0.10.0" } @@ -8476,6 +8500,14 @@ "node": ">=0.10.0" } }, + "node_modules/static-eval": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/static-eval/-/static-eval-2.0.2.tgz", + "integrity": "sha512-N/D219Hcr2bPjLxPiV+TQE++Tsmrady7TqAJugLy7Xk1EumfDWS/f5dtBbkRCGE7wKKXuYockQoj8Rm2/pVKyg==", + "dependencies": { + "escodegen": "^1.8.1" + } + }, "node_modules/static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -8908,7 +8940,6 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", - "dev": true, "dependencies": { "prelude-ls": "~1.1.2" }, @@ -8956,6 +8987,11 @@ "node": ">=4.2.0" } }, + "node_modules/underscore": { + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.1.tgz", + "integrity": "sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==" + }, "node_modules/union-value": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", @@ -9200,7 +9236,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", - "dev": true, "engines": { "node": ">=0.10.0" } diff --git a/package.json b/package.json index 8e7a030..9aff28d 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { + "@json-schema-tools/validator": "^1.4.0", "@open-rpc/schema-utils-js": "^1.14.0", "@types/isomorphic-fetch": "0.0.35", "@types/lodash": "^4.14.162", diff --git a/src/coverage.ts b/src/coverage.ts index bfbd510..30c5538 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -8,7 +8,7 @@ import { MethodObjectParams } from "@open-rpc/meta-schema"; const jsf = require("json-schema-faker"); // tslint:disable-line -import Ajv from "ajv"; +import validate from "@json-schema-tools/validator"; import { isEqual } from "lodash"; const getFakeParams = (params: any[]): any[] => { @@ -94,12 +94,12 @@ export default async (options: IOptions) => { if (exampleCall.expectedResult) { exampleCall.valid = isEqual(exampleCall.expectedResult, exampleCall.result); } else { - const ajv = new Ajv(); - ajv.validate(exampleCall.resultSchema, exampleCall.result); - if (ajv.errors && ajv.errors.length > 0) { + const errors = validate(exampleCall.resultSchema, exampleCall.result); + console.log('errors', exampleCall, errors); + if (Array.isArray(errors) && errors.length > 0) { exampleCall.valid = false; - exampleCall.reason = JSON.stringify(ajv.errors); - } else { + exampleCall.reason = JSON.stringify(errors); + } else if (errors === true) { exampleCall.valid = true; } } diff --git a/src/reporters/console.ts b/src/reporters/console.ts index ffd2a2c..7f2fca4 100644 --- a/src/reporters/console.ts +++ b/src/reporters/console.ts @@ -3,7 +3,7 @@ import { OpenrpcDocument, JSONSchemaObject, } from "@open-rpc/meta-schema"; -import {ExampleCall} from "../coverage"; +import type { ExampleCall } from "../coverage"; import _ from "lodash"; const getExpectedString = (ex: ExampleCall) => {