Class: JSONRPC::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonrpc/validator.rb

Overview

Validates JSON-RPC 2.0 requests, notifications and batches

The Validator handles parameter validation for JSON-RPC requests by checking method signatures against registered procedure definitions using Dry::Validation contracts.

Examples:

Validate a single request

validator = JSONRPC::Validator.new
error = validator.validate(request)

Instance Method Summary collapse

Instance Method Details

#validate(batch_or_request) ⇒ JSONRPC::Error, ...

Validates a single request, notification or a batch

Examples:

Validate a single request

validator = JSONRPC::Validator.new
error = validator.validate(request)

Validate a batch of requests

validator = JSONRPC::Validator.new
errors = validator.validate(batch)

Parameters:

Returns:



32
33
34
35
36
37
38
39
# File 'lib/jsonrpc/validator.rb', line 32

def validate(batch_or_request)
  case batch_or_request
  when BatchRequest
    validate_batch_params(batch_or_request)
  when Request, Notification
    validate_request_params(batch_or_request)
  end
end