Class: JSON::Fuzz::Generator::Keyword::Required

Inherits:
Object
  • Object
show all
Defined in:
lib/json/fuzz/generator/keyword/required.rb

Class Method Summary collapse

Class Method Details

.invalid_params(attributes) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json/fuzz/generator/keyword/required.rb', line 7

def invalid_params(attributes)
  required_properties = attributes["required"]
  raise "No required keyword given: #{attributes}" unless required_properties

  generated_params = []

  required_properties.each do |property|
    template = JSON::Fuzz::Generator.default_param(attributes)
    template.delete(property)
    generated_params << template
  end

  generated_params
end

.valid_param(attributes) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/json/fuzz/generator/keyword/required.rb', line 22

def valid_param(attributes)
  required_properties = attributes["required"]
  raise "No required keyword given: #{attributes}" unless required_properties

  generated_param = {}

  required_properties.each do |property|
    properties_key = attributes.key?("members") ? "members" : "properties"
    attribute = attributes[properties_key][property]
    generated_param[property] = JSON::Fuzz::Generator.default_param(attribute)
  end
  
  generated_param
end