Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MethodCallValidator

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.

Hierarchy

  • MethodCallValidator

Index

Constructors

Methods

Constructors

constructor

  • example
    
    import { petstore } from "@open-rpc/examples";
    const petStoreMethodCallValidator = new MethodCallValidator(petstore);
    // Go on and use it!

    Parameters

    • document: OpenRPC

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

    Returns MethodCallValidator

Methods

validate

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

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

    Parameters

    • methodName: string

      the name of the method in the OpenRPC Document.

    • params: any[]

      the param values that you want validated.

    Returns ParameterValidationError[] | MethodNotFoundError

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