Class JSON::Schema::Reader
In: lib/json-schema/schema/reader.rb
Parent: Object

When an unregistered schema is encountered, the {JSON::Schema::Reader} is used to fetch its contents and register it with the {JSON::Validator}.

This default reader will read schemas from the filesystem or from a URI.

Methods

accept_file?   accept_uri?   new   read  

Public Class methods

The behavior of the schema reader can be controlled by providing callbacks to determine whether to permit reading referenced schemas. The options accept_uri and accept_file should be procs which accept a URI or Pathname object, and return a boolean value indicating whether to read the referenced schema.

URIs using the file scheme will be normalized into Pathname objects and passed to the accept_file callback.

@param options [Hash] @option options [Boolean, call] accept_uri (true) @option options [Boolean, call] accept_file (true)

@example Reject all unregistered schemas

  JSON::Validator.schema_reader = JSON::Schema::Reader.new(
    :accept_uri => false,
    :accept_file => false
  )

@example Only permit URIs from certain hosts

  JSON::Validator.schema_reader = JSON::Schema::Reader.new(
    :accept_file => false,
    :accept_uri => proc { |uri| ['mycompany.com', 'json-schema.org'].include?(uri.host) }
  )

Public Instance methods

@param pathname [Pathname] @return [Boolean]

@param uri [Addressable::URI] @return [Boolean]

@param location [to_s] The location from which to read the schema @return [JSON::Schema] @raise [JSON::Schema::ReadRefused] if accept_uri or accept_file

  indicated the schema could not be read

@raise [JSON::Schema::ParseError] if the schema was not a valid JSON object

[Validate]