Class: JSON::Validator

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

Instance Method Summary collapse

Instance Method Details

#load_ref_schema(parent_schema, ref) ⇒ Object

Patches json-schema(<2.5) gem to work on Windows

Author:

  • Josh Bradley



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/adiwg/mdjson_schemas/validator.rb', line 11

def load_ref_schema(parent_schema,ref)
  uri = URI.parse(ref)
  if uri.relative?
    uri = parent_schema.uri.clone

    # Check for absolute path
    path = ref.split("#")[0]

    # This is a self reference and thus the schema does not need to be
    # re-loaded
    if path.nil? || path == ''
    return
    end

    if path && path[0,1] == '/'
      uri.path = Pathname.new(path).cleanpath.to_s
    else
    uri = parent_schema.uri.merge(path)
    end
    uri.fragment = ''
  end

  if Validator.schemas[uri.to_s].nil?
    schema = JSON::Schema.new(JSON::Validator.parse(open(uri.to_s.chomp('#')).read), uri, @options[:version])
    Validator.add_schema(schema)
    build_schemas(schema)
  end
end