Module: SimpleJSONSchema::PropertiesHelper

Defined in:
lib/simple_json_schema/properties_helper.rb

Class Method Summary collapse

Class Method Details

.checkers(scope) ⇒ Object



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

def checkers(scope)
  Checker.required_keys(scope)
  Checker.at_size(scope, :maxProperties, :>)
  Checker.at_size(scope, :minProperties, :<)
end

.each_dependency(scope) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_json_schema/properties_helper.rb', line 12

def each_dependency(scope)
  dependencies = scope[:dependencies]
  return unless dependencies.is_a?(Hash)

  value = scope.value
  return unless value.is_a?(Hash)

  dependencies.each_key do |dependency|
    next unless value.key?(dependency)

    yield([:dependencies, dependency])
  end
end

.each_property_name(scope, &block) ⇒ Object



40
41
42
43
44
45
# File 'lib/simple_json_schema/properties_helper.rb', line 40

def each_property_name(scope, &block)
  property_names = scope[:propertyNames]
  return if property_names.nil?

  scope.value.each_key(&block)
end

.map_property_schema_path(scope, property_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/simple_json_schema/properties_helper.rb', line 47

def map_property_schema_path(scope, property_name)
  paths = []
  paths << [:properties, property_name] if scope[:properties]&.key?(property_name)

  if scope.key?(:patternProperties)
    select_patten_properties(scope, property_name).each do |pattern|
      paths << [:patternProperties, pattern]
    end
  end

  paths << [:additionalProperties] if paths.empty? && scope.key?(:additionalProperties)
  paths
end

.processe_defualt(scope) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/simple_json_schema/properties_helper.rb', line 26

def processe_defualt(scope)
  return unless scope.options[:insert_defaults] == true

  properties = scope[:properties]
  return unless properties

  value = scope.value
  properties.each do |property_name, property_schema|
    if !value.key?(property_name) && property_schema.is_a?(Hash) && property_schema.key?('default')
      value[property_name] = property_schema.fetch('default').clone
    end
  end
end