lib/json-schema/schema/reader.rb
# 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) }
#   )
The behavior of the schema reader can be controlled by providing
callbacks to determine whether to permit reading referenced schemas.


The behavior of the schema reader can be controlled by providing callbacks to determine whether to permit reading referenced schemas .
def read_file(pathname)
        if accept_file?(pathname)
          File.read(JSON::Util::URI.unescaped_path(pathname.to_s))
        else
          raise JSON::Schema::ReadRefused.new(pathname.to_s, :file)
        end
      rescue Errno::ENOENT
        raise JSON::Schema::ReadFailed.new(pathname.to_s, :file)
      end
def read_file ( pathname ) if accept_file? ( pathname ) File . read ( JSON :: Util :: URI . unescaped_path ( pathname . to_s ) ) else raise JSON :: Schema :: ReadRefused . new ( pathname . to_s , :file ) end rescue Errno :: ENOENT raise JSON :: Schema :: ReadFailed . new ( pathname . to_s , :file ) end
The behavior of the schema reader can be controlled by providing
callbacks to determine whether to permit reading referenced schemas.
The behavior of the schema reader can be controlled by providing callbacks to determine whether to permit reading referenced schemas .
pathname
<not_specific>
<not_specific>
None
options
<not_specific>
None
example
Reject all unregistered schemas JSON::Validator.schema_reader = JSON::Schema::Reader.new( :accept_uri => false, :accept_file => false )
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) } )
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 ) } )