Class: JSON::Fuzz::Generator::Keyword::MaxProperties
- Inherits:
-
Object
- Object
- JSON::Fuzz::Generator::Keyword::MaxProperties
- Defined in:
- lib/json/fuzz/generator/keyword/max_properties.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/max_properties.rb', line 7 def invalid_params(attributes) max_properties = attributes["maxProperties"] raise "No maxProperties keyword given: #{attributes}" unless max_properties generated_params = [] invalid_param = {} template = valid_param(attributes) while template.size <= max_properties key = /\w+/.gen template[key] = template[template.keys.sample] end [template] end |
.valid_param(attributes) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/json/fuzz/generator/keyword/max_properties.rb', line 24 def valid_param(attributes) attributes = Marshal.load(Marshal.dump(attributes)) max_properties = attributes.delete("maxProperties") raise "No maxProperties keyword given: #{attributes}" unless max_properties template = JSON::Fuzz::Generator.default_param(attributes) while template.size > max_properties requred_keys = attributes["required"] || [] key = (template.keys - requred_keys).sample template.delete(template.keys.sample) end template end |