Class: JSON::Fuzz::Generator::Keyword::AllOf

Inherits:
Object
  • Object
show all
Defined in:
lib/json/fuzz/generator/keyword/all_of.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
21
22
23
24
25
26
# File 'lib/json/fuzz/generator/keyword/all_of.rb', line 7

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

  generated_params = []

  all_of.each do |schema|
    JSON::Fuzz::Generator.generate(schema).each do |invalid_param|
      if invalid_param.empty?
        generated_params << invalid_param
      else
        template = valid_param(attributes)
        template.merge!(invalid_param)
        generated_params << template
      end
    end
  end

  generated_params
end

.valid_param(attributes) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/json/fuzz/generator/keyword/all_of.rb', line 28

def valid_param(attributes)
  attributes = Marshal.load(Marshal.dump(attributes))
  all_of = attributes.delete("allOf")
  raise "No allOf keyword given: #{attributes}" unless all_of
  
  generated_param = {}

  all_of.each do |schema|
    generated_param.merge!(JSON::Fuzz::Generator.default_param(schema))
  end

  generated_param
end