Module: SimpleJSONSchema::ItemsHelper

Defined in:
lib/simple_json_schema/items_helper.rb

Class Method Summary collapse

Class Method Details

.checkers(scope) ⇒ Object



6
7
8
9
10
# File 'lib/simple_json_schema/items_helper.rb', line 6

def checkers(scope)
  Checker.at_size(scope, :maxItems, :>)
  Checker.at_size(scope, :minItems, :<)
  Checker.unique_items(scope)
end

.contains_in_items?(scope, &block) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/simple_json_schema/items_helper.rb', line 12

def contains_in_items?(scope, &block)
  contains = scope[:contains]
  return if contains.nil?

  scope.error(:contains) unless scope.value.each_index.any?(&block)
end

.each_path(scope) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/simple_json_schema/items_helper.rb', line 19

def each_path(scope)
  items = scope[:items]
  additional_items = scope[:additionalItems]
  many_types = items.is_a?(Array)

  scope.value.each_index do |index|
    if many_types
      if index < items.size
        yield [:items, index], index
      elsif !additional_items.nil?
        yield [:additionalItems], index
      else
        break # protect over big arrays.
      end
    else
      yield [:items], index
    end
  end
end