Class: JSON::Fuzz::Generator::Keyword::AnyOf

Inherits:
Object
  • Object
show all
Defined in:
lib/json/fuzz/generator/keyword/any_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
# File 'lib/json/fuzz/generator/keyword/any_of.rb', line 7

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

  generated_params = []

  any_of.each do |schema|
    temp_params = JSON::Fuzz::Generator.generate(schema).reject do |param|
      ::JSON::Validator.validate(attributes, param)
    end
    temp_params.each {|e| generated_params << e}
  end

  raise "failed to generate invalid_params for schema: #{attributes}" if generated_params.empty?
  generated_params.uniq
end

.valid_param(attributes) ⇒ Object



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

def valid_param(attributes)
  attributes = Marshal.load(Marshal.dump(attributes))
  any_of = attributes.delete("anyOf")
  raise "No anyOf keyword given: #{attributes}" unless any_of
  
  generated_params = []

  any_of.each do |valid_schema|
    generated_param = JSON::Fuzz::Generator.default_param(valid_schema)
    generated_params << generated_param
  end

  generated_params.sample
end