Class: JsonSchema::ReferenceExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schema/reference_expander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/json_schema/reference_expander.rb', line 5

def errors
  @errors
end

Instance Method Details

#expand(schema, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/json_schema/reference_expander.rb', line 7

def expand(schema, options = {})
  @errors = []
  @schema = schema
  @store  = options[:store] ||= DocumentStore.new

  @store.add_uri_reference("/", schema)

  traverse_schema(schema)

  refs = unresolved_refs(schema).sort
  if refs.count > 0
    message = %{Couldn't resolve references: #{refs.to_a.join(", ")}.}
    @errors << SchemaError.new(schema, message)
  end

  @errors.count == 0
end

#expand!(schema) ⇒ Object



25
26
27
28
29
30
# File 'lib/json_schema/reference_expander.rb', line 25

def expand!(schema)
  if !expand(schema)
    raise SchemaError.aggregate(@errors)
  end
  true
end