Class: JSONSchemer::Fuzz::PrimitiveType::Integer
- Inherits:
-
Object
- Object
- JSONSchemer::Fuzz::PrimitiveType::Integer
- Defined in:
- lib/json_schemer/fuzz/primitive_type/integer.rb
Class Method Summary collapse
- .invalid_params(attributes) ⇒ Object
- .keyword_to_class_map ⇒ Object
- .valid_param(attributes = {}) ⇒ Object
Class Method Details
.invalid_params(attributes) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/json_schemer/fuzz/primitive_type/integer.rb', line 6 def invalid_params(attributes) generated_params = [] if type = attributes["type"] valid_types = [type].flatten # TODO: Ideally this array would include a string number, as that is the intent here ["&"].each { |val| generated_params << val } unless valid_types.include?("string") # TODO: Ideally 0.1 would work here as invalid, as it is not an integer # But it doesn't, so instead we use an array generated_params << [0.1] unless valid_types.include?("number") JSONSchemer::Fuzz::PrimitiveType.invalid_params_by_type(attributes).each do |invalid_param| generated_params << invalid_param end else generated_params = ["#"] end attributes.each do |keyword, attribute| if (klass = keyword_to_class_map[keyword]) klass.invalid_params(attributes).each do |invalid_param| generated_params << invalid_param end end end generated_params end |
.keyword_to_class_map ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/json_schemer/fuzz/primitive_type/integer.rb', line 44 def keyword_to_class_map { "minimum" => JSONSchemer::Fuzz::Keyword::Minimum, "maximum" => JSONSchemer::Fuzz::Keyword::Maximum, "multipleOf" => JSONSchemer::Fuzz::Keyword::MultipleOf, } end |
.valid_param(attributes = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/json_schemer/fuzz/primitive_type/integer.rb', line 33 def valid_param(attributes = {}) valid_params = [] attributes.each do |keyword, attribute| if klass = keyword_to_class_map[keyword] valid_params << klass.valid_param(attributes) end end valid_params.empty? ? rand(100) : valid_params.sample end |