A class to assist in validating method calls to an OpenRPC-based service. Generated Clients, Servers, and many others may want to expose the interface provided by an OpenRPC document. In doing so, use this class to easily create a re-useable validator for a particular method.

Constructors

Properties

Methods

Constructors

Properties

ajvValidator: Ajv
document: OpenrpcDocument

The OpenRPC document containing the methods whose calls we want validated.

Methods

  • Validates a particular method call against the OpenRPC definition for the method.

    Parameters

    • methodName: string

      the name of the method in the OpenRPC Document.

    • params: any

      the param values that you want validated.

    Returns MethodNotFoundError | ParameterValidationError[]

    an array of parameter validation errors, or if there are none, an empty array. if the method name is invalid, a [[MethodNotFoundError]] is returned.

    Example


    import { petstore } from "@open-rpc/examples";
    const petStoreMethodCallValidator = new MethodCallValidator(petstore);
    const errors = petStoreMethodCallValidator.validate("list_pets", []);
    // errors.length === 0