Skip to content
Open
Show file tree
Hide file tree
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
168 changes: 144 additions & 24 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"@json-schema-tools/reference-resolver": "^1.2.6",
"@open-rpc/meta-schema": "^1.14.9",
"@open-rpc/specification-extension-spec": "^1.0.2",
"ajv": "^6.10.0",
"ajv": "^8.18.0",
"ajv-formats": "^3.0.1",
"detect-node": "^2.0.4",
"fast-safe-stringify": "^2.0.7",
"fs-extra": "^10.1.0",
Expand Down
6 changes: 4 additions & 2 deletions src/method-call-validator/method-call-validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ajv, { ErrorObject, Ajv as IAjv } from "ajv";
import Ajv, { ErrorObject } from "ajv";
import addFormats from "ajv-formats";
import { generateMethodParamId } from "../generate-method-id";
import ParameterValidationError from "./parameter-validation-error";
import {
Expand All @@ -17,7 +18,7 @@ import MethodRefUnexpectedError from "./method-ref-unexpected-error";
* In doing so, use this class to easily create a re-useable validator for a particular method.
*/
export default class MethodCallValidator {
private ajvValidator: IAjv;
private ajvValidator: Ajv;

/**
* @param document The OpenRPC document containing the methods whose calls we want validated.
Expand All @@ -33,6 +34,7 @@ export default class MethodCallValidator {
*/
constructor(private document: OpenRPC) {
this.ajvValidator = new Ajv();
addFormats(this.ajvValidator);

// Validate that the methods are dereferenced
document.methods.forEach((method: MethodOrReference) => {
Expand Down
3 changes: 2 additions & 1 deletion src/method-call-validator/parameter-validation-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { ErrorObject } from "ajv";

describe("ParameterValidationError", () => {
const errorObj = {
dataPath: "abc",
instancePath: "abc",
keyword: "123",
params: {},
schemaPath: "1/2/3",
message: "test error",
} as ErrorObject;

it("can be instantiated", () => {
Expand Down
4 changes: 3 additions & 1 deletion src/validate-open-rpc-document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenrpcDocument as OpenRPC } from "@open-rpc/meta-schema";
import Ajv, { ErrorObject } from "ajv";
import addFormats from "ajv-formats";
import JsonSchemaMetaSchema from "@json-schema-tools/meta-schema";
import applyExtensionSpec from "./apply-extension-spec";
import getExtendedMetaSchema from "./get-extended-metaschema";
Expand Down Expand Up @@ -51,7 +52,8 @@ export class OpenRPCDocumentValidationError implements Error {
export default function validateOpenRPCDocument(
document: OpenRPC
): OpenRPCDocumentValidationError | true {
const ajv = new Ajv();
const ajv = new Ajv({ strict: false });
addFormats(ajv);
ajv.addSchema(JsonSchemaMetaSchema, "https://meta.json-schema.tools");
let extMetaSchema = getExtendedMetaSchema();
try {
Expand Down