Skip to content

feat: use json-schema-tools validator instead of ajv #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
12 changes: 6 additions & 6 deletions src/coverage.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
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 @@
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);

Check warning on line 98 in src/coverage.ts

Codecov / codecov/patch

src/coverage.ts#L98

Added line #L98 was not covered by tests
if (Array.isArray(errors) && errors.length > 0) {
exampleCall.valid = false;
exampleCall.reason = JSON.stringify(ajv.errors);
} else {
exampleCall.reason = JSON.stringify(errors);

Check warning on line 101 in src/coverage.ts

Codecov / codecov/patch

src/coverage.ts#L101

Added line #L101 was not covered by tests
} else if (errors === true) {
exampleCall.valid = true;
}
}
2 changes: 1 addition & 1 deletion src/reporters/console.ts
Original file line number Diff line number Diff line change
@@ -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) => {