From 07921d48ee75d6c8c24427117126067c91a10e81 Mon Sep 17 00:00:00 2001 From: Naoki Shimizu Date: Sun, 3 Aug 2014 15:59:47 +0900 Subject: [PATCH 1/5] 1st desigin --- fuzz-json-schema.gemspec | 4 +++- lib/fuzz-json-schema.rb | 2 ++ lib/fuzz/json/generator.rb | 14 ++++++++++++++ lib/fuzz/json/schema.rb | 7 ++----- lib/fuzz/json/schema/version.rb | 4 ++-- spec/fuzz/json/schema_spec.rb | 17 +++++++++++------ spec/schemas/base_schema.json | 8 ++++++++ spec/spec_helper.rb | 7 ++++++- 8 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 lib/fuzz-json-schema.rb create mode 100644 lib/fuzz/json/generator.rb create mode 100644 spec/schemas/base_schema.json diff --git a/fuzz-json-schema.gemspec b/fuzz-json-schema.gemspec index 067b5f0..58aaf8e 100644 --- a/fuzz-json-schema.gemspec +++ b/fuzz-json-schema.gemspec @@ -5,7 +5,7 @@ require 'fuzz/json/schema/version' Gem::Specification.new do |spec| spec.name = "fuzz-json-schema" - spec.version = Fuzz::Json::Schema::VERSION + spec.version = Fuzz::JSON::Schema::VERSION spec.authors = ["deme0607"] spec.email = ["hcs0035@gmail.com"] spec.summary = %q{Fuzz parameter gemerator from json-schema} @@ -21,4 +21,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.6" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" + spec.add_development_dependency "pry-byebug" + spec.add_development_dependency "json-schema" end diff --git a/lib/fuzz-json-schema.rb b/lib/fuzz-json-schema.rb new file mode 100644 index 0000000..3e50140 --- /dev/null +++ b/lib/fuzz-json-schema.rb @@ -0,0 +1,2 @@ +require "fuzz/json/schema" +require "fuzz/json/generator" diff --git a/lib/fuzz/json/generator.rb b/lib/fuzz/json/generator.rb new file mode 100644 index 0000000..e3a2ceb --- /dev/null +++ b/lib/fuzz/json/generator.rb @@ -0,0 +1,14 @@ +module Fuzz + module JSON + class Generator + class << self + def generate(json_schema) + [ + {"id" => "a"}, + {"id" => "1"}, + ] + end + end + end + end +end diff --git a/lib/fuzz/json/schema.rb b/lib/fuzz/json/schema.rb index f17639f..614ca01 100644 --- a/lib/fuzz/json/schema.rb +++ b/lib/fuzz/json/schema.rb @@ -1,9 +1,6 @@ -require "fuzz/json/schema/version" - module Fuzz - module Json - module Schema - # Your code goes here... + module JSON + class Schema end end end diff --git a/lib/fuzz/json/schema/version.rb b/lib/fuzz/json/schema/version.rb index 74ced66..c3e60b5 100644 --- a/lib/fuzz/json/schema/version.rb +++ b/lib/fuzz/json/schema/version.rb @@ -1,6 +1,6 @@ module Fuzz - module Json - module Schema + module JSON + class Schema VERSION = "0.0.1" end end diff --git a/spec/fuzz/json/schema_spec.rb b/spec/fuzz/json/schema_spec.rb index b5a14da..b7726d7 100644 --- a/spec/fuzz/json/schema_spec.rb +++ b/spec/fuzz/json/schema_spec.rb @@ -1,11 +1,16 @@ require 'spec_helper' -describe Fuzz::Json::Schema do - it 'has a version number' do - expect(Fuzz::Json::Schema::VERSION).not_to be nil - end +describe Fuzz::JSON do + context "basic features" do + it "integer works" do + schema_file = File.join(SPEC_SCHEMA_ROOT, "base_schema.json") + fuzz_params_list = Fuzz::JSON::Generator.generate(schema_file) - it 'does something useful' do - expect(false).to eq(true) + fuzz_params_list.each do |params| + expect(params).to include("id") + result = JSON::Validator.validate(schema_file, params) + expect(result).to eq(false) + end + end end end diff --git a/spec/schemas/base_schema.json b/spec/schemas/base_schema.json new file mode 100644 index 0000000..3228a27 --- /dev/null +++ b/spec/schemas/base_schema.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "id" : { + "type": "integer" + } + } +} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d95cc0..f3d68e3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,7 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) -require 'fuzz/json/schema' +require 'fuzz-json-schema' +require 'pry' +require 'json-schema' + +SPEC_ROOT = File.expand_path(File.dirname(__FILE__), ".") +SPEC_SCHEMA_ROOT = File.join(SPEC_ROOT, "schemas") From d7c4a96b4cc62fd7ccac9b295172ac47f7c2854e Mon Sep 17 00:00:00 2001 From: Naoki Shimizu Date: Mon, 4 Aug 2014 00:55:11 +0900 Subject: [PATCH 2/5] basic moch --- lib/fuzz-json-schema.rb | 3 +++ lib/fuzz/json/generator.rb | 40 +++++++++++++++++++++++++--- lib/fuzz/json/generator/minimum.rb | 19 +++++++++++++ lib/fuzz/json/generator/propaties.rb | 25 +++++++++++++++++ lib/fuzz/json/generator/type.rb | 21 +++++++++++++++ spec/fuzz/json/schema_spec.rb | 4 +-- spec/schemas/base_schema.json | 21 ++++++++++----- 7 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 lib/fuzz/json/generator/minimum.rb create mode 100644 lib/fuzz/json/generator/propaties.rb create mode 100644 lib/fuzz/json/generator/type.rb diff --git a/lib/fuzz-json-schema.rb b/lib/fuzz-json-schema.rb index 3e50140..34adc9e 100644 --- a/lib/fuzz-json-schema.rb +++ b/lib/fuzz-json-schema.rb @@ -1,2 +1,5 @@ +require "json-schema" require "fuzz/json/schema" require "fuzz/json/generator" + +Dir[File.join(File.dirname(__FILE__), "fuzz/json/generator/*.rb")].each {|file| require file } diff --git a/lib/fuzz/json/generator.rb b/lib/fuzz/json/generator.rb index e3a2ceb..7cee2c1 100644 --- a/lib/fuzz/json/generator.rb +++ b/lib/fuzz/json/generator.rb @@ -3,12 +3,44 @@ module JSON class Generator class << self def generate(json_schema) - [ - {"id" => "a"}, - {"id" => "1"}, - ] + generator = Fuzz::JSON::Generator.new + generator.generate(json_schema) end end + + attr_accessor :generators + + def initialize + @generators = {} + @generators["type"] = Fuzz::JSON::Generator::TypeAttribute.new + @generators["properties"] = Fuzz::JSON::Generator::PropertiesAttribute.new + @generators["minimum"] = Fuzz::JSON::Generator::MinimumAttribute.new + end + + def generate(schema) + json_schema = ::JSON::Validator.parse(open(schema).read) + generated_params = [] + valid_param = default_param(schema) + + json_schema.each do |attr_name, attribute| + if @generators.key?(attr_name) + invalid_params = @generators[attr_name].generate(json_schema, self) + if invalid_params + invalid_params.each { |param| generated_params.push(valid_param.merge(param)) } + end + end + end + + generated_params + end + + def default_param(schema) + { + "id" => 1, + "name" => "deme0607", + "age" => 27, + } + end end end end diff --git a/lib/fuzz/json/generator/minimum.rb b/lib/fuzz/json/generator/minimum.rb new file mode 100644 index 0000000..4dea5fd --- /dev/null +++ b/lib/fuzz/json/generator/minimum.rb @@ -0,0 +1,19 @@ +module Fuzz + module JSON + class Generator + class MinimumAttribute + def generate(properties, generator) + type = properties["type"] + minimum_value = properties["minimum"] + + case type + when "integer" + [minimum_value - 1] + else + warn "not impremented type: #{type}" + end + end + end + end + end +end diff --git a/lib/fuzz/json/generator/propaties.rb b/lib/fuzz/json/generator/propaties.rb new file mode 100644 index 0000000..f6ae48e --- /dev/null +++ b/lib/fuzz/json/generator/propaties.rb @@ -0,0 +1,25 @@ +module Fuzz + module JSON + class Generator + class PropertiesAttribute + def generate(attributes, generator) + generated_params = [] + attribute = attributes["properties"] + + attribute.each do |key, properties| + properties.each do |property_name, property| + if generator.generators.key?(property_name) + invalid_params = generator.generators[property_name].generate(properties, generator) + if invalid_params + invalid_params.each { |param| generated_params.push( {key => param} ) } + end + end + end + end + + generated_params + end + end + end + end +end diff --git a/lib/fuzz/json/generator/type.rb b/lib/fuzz/json/generator/type.rb new file mode 100644 index 0000000..a48a9f1 --- /dev/null +++ b/lib/fuzz/json/generator/type.rb @@ -0,0 +1,21 @@ +module Fuzz + module JSON + class Generator + class TypeAttribute + def generate(properties, generator) + attribute = properties["type"] + case attribute + when "object" + nil + when "integer" + ["1", "a"] + when "string" + [1] + else + warn "not impremented attribute: #{attribute}" + end + end + end + end + end +end diff --git a/spec/fuzz/json/schema_spec.rb b/spec/fuzz/json/schema_spec.rb index b7726d7..02bfccc 100644 --- a/spec/fuzz/json/schema_spec.rb +++ b/spec/fuzz/json/schema_spec.rb @@ -3,11 +3,11 @@ describe Fuzz::JSON do context "basic features" do it "integer works" do - schema_file = File.join(SPEC_SCHEMA_ROOT, "base_schema.json") + schema_file = File.join(SPEC_SCHEMA_ROOT, "basic_schema.json") fuzz_params_list = Fuzz::JSON::Generator.generate(schema_file) fuzz_params_list.each do |params| - expect(params).to include("id") + expect(params).to include("id", "name", "age") result = JSON::Validator.validate(schema_file, params) expect(result).to eq(false) end diff --git a/spec/schemas/base_schema.json b/spec/schemas/base_schema.json index 3228a27..562c2e1 100644 --- a/spec/schemas/base_schema.json +++ b/spec/schemas/base_schema.json @@ -1,8 +1,17 @@ { - "type": "object", - "properties": { - "id" : { - "type": "integer" - } - } + "title": "Basic Schema", + "type": "object", + "properties": { + "id" : { + "type": "integer" + }, + "name": { + "type": "string" + }, + "age": { + "description": "Age in years", + "type": "integer", + "minimum": 0 + } + } } From 5c691260aea7f15a03030358d4c39f763d759f5d Mon Sep 17 00:00:00 2001 From: Naoki Shimizu Date: Mon, 4 Aug 2014 00:56:46 +0900 Subject: [PATCH 3/5] fix --- spec/schemas/{base_schema.json => basic_schema.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/schemas/{base_schema.json => basic_schema.json} (100%) diff --git a/spec/schemas/base_schema.json b/spec/schemas/basic_schema.json similarity index 100% rename from spec/schemas/base_schema.json rename to spec/schemas/basic_schema.json From 175336e119ad76c8e8876deb27654e8347317a8e Mon Sep 17 00:00:00 2001 From: Naoki Shimizu Date: Thu, 7 Aug 2014 09:42:00 +0900 Subject: [PATCH 4/5] design --- lib/fuzz/json/generator.rb | 44 +++++++++++-------- lib/fuzz/json/generator/primitive_type.rb | 1 + .../json/generator/primitive_type/array.rb | 18 ++++++++ .../json/generator/primitive_type/boolean.rb | 18 ++++++++ .../json/generator/primitive_type/integer.rb | 18 ++++++++ .../json/generator/primitive_type/null.rb | 18 ++++++++ .../json/generator/primitive_type/number.rb | 18 ++++++++ .../json/generator/primitive_type/object.rb | 42 ++++++++++++++++++ .../json/generator/primitive_type/string.rb | 18 ++++++++ lib/fuzz/json/generator/type.rb | 10 ++++- spec/fuzz/json/schema_spec.rb | 20 ++++++++- spec/schemas/primitive_types.json | 35 +++++++++++++++ 12 files changed, 239 insertions(+), 21 deletions(-) create mode 100644 lib/fuzz/json/generator/primitive_type.rb create mode 100644 lib/fuzz/json/generator/primitive_type/array.rb create mode 100644 lib/fuzz/json/generator/primitive_type/boolean.rb create mode 100644 lib/fuzz/json/generator/primitive_type/integer.rb create mode 100644 lib/fuzz/json/generator/primitive_type/null.rb create mode 100644 lib/fuzz/json/generator/primitive_type/number.rb create mode 100644 lib/fuzz/json/generator/primitive_type/object.rb create mode 100644 lib/fuzz/json/generator/primitive_type/string.rb create mode 100644 spec/schemas/primitive_types.json diff --git a/lib/fuzz/json/generator.rb b/lib/fuzz/json/generator.rb index 7cee2c1..4703c2b 100644 --- a/lib/fuzz/json/generator.rb +++ b/lib/fuzz/json/generator.rb @@ -11,35 +11,43 @@ def generate(json_schema) attr_accessor :generators def initialize - @generators = {} - @generators["type"] = Fuzz::JSON::Generator::TypeAttribute.new - @generators["properties"] = Fuzz::JSON::Generator::PropertiesAttribute.new - @generators["minimum"] = Fuzz::JSON::Generator::MinimumAttribute.new + @generators = { + "array" => Fuzz::JSON::Generator::PrimitiveType::Array.new, + "boolean" => Fuzz::JSON::Generator::PrimitiveType::Boolean.new, + "integer" => Fuzz::JSON::Generator::PrimitiveType::Integer.new, + "null" => Fuzz::JSON::Generator::PrimitiveType::Null.new, + "number" => Fuzz::JSON::Generator::PrimitiveType::Number.new, + "object" => Fuzz::JSON::Generator::PrimitiveType::Object.new, + "string" => Fuzz::JSON::Generator::PrimitiveType::String.new, + } end def generate(schema) - json_schema = ::JSON::Validator.parse(open(schema).read) + schema = ::JSON::Validator.parse(open(schema).read) if schema.instance_of?(String) generated_params = [] - valid_param = default_param(schema) - - json_schema.each do |attr_name, attribute| - if @generators.key?(attr_name) - invalid_params = @generators[attr_name].generate(json_schema, self) - if invalid_params - invalid_params.each { |param| generated_params.push(valid_param.merge(param)) } - end + + if type = schema["type"] + @generators[type].invalid_params(schema, self).each do |invalid_param| + generated_params.push(invalid_param) end + else + raise "No Type" end generated_params end def default_param(schema) - { - "id" => 1, - "name" => "deme0607", - "age" => 27, - } + generated_param = nil; + schema = ::JSON::Validator.parse(open(schema).read) if schema.instance_of?(String) + + if type = schema["type"] + generated_param = @generators[type].valid_param(schema, self) + else + raise "No Type" + end + + generated_param end end end diff --git a/lib/fuzz/json/generator/primitive_type.rb b/lib/fuzz/json/generator/primitive_type.rb new file mode 100644 index 0000000..1538c44 --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type.rb @@ -0,0 +1 @@ +Dir[File.join(File.dirname(__FILE__), "primitive_type/*.rb")].each {|file| require file } diff --git a/lib/fuzz/json/generator/primitive_type/array.rb b/lib/fuzz/json/generator/primitive_type/array.rb new file mode 100644 index 0000000..33a41b2 --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/array.rb @@ -0,0 +1,18 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class Array + def invalid_params(attributes, generator) + [{}] + end + + def valid_param(attributes, generator) + ["sample", "array"] + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/primitive_type/boolean.rb b/lib/fuzz/json/generator/primitive_type/boolean.rb new file mode 100644 index 0000000..9db5064 --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/boolean.rb @@ -0,0 +1,18 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class Boolean + def invalid_params(attributes, generator) + ["true", "false", "1", "0"] + end + + def valid_param(attributes, generator) + [true, false].sample + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/primitive_type/integer.rb b/lib/fuzz/json/generator/primitive_type/integer.rb new file mode 100644 index 0000000..ee114a4 --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/integer.rb @@ -0,0 +1,18 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class Integer + def invalid_params(attributes, generator) + ["a", "1"] + end + + def valid_param(attributes, generator) + rand(100) + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/primitive_type/null.rb b/lib/fuzz/json/generator/primitive_type/null.rb new file mode 100644 index 0000000..38c95a4 --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/null.rb @@ -0,0 +1,18 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class Null + def invalid_params(attributes, generator) + ["nil", "0", "null", false, ""] + end + + def valid_param(attributes, generator) + nil + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/primitive_type/number.rb b/lib/fuzz/json/generator/primitive_type/number.rb new file mode 100644 index 0000000..b0d761f --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/number.rb @@ -0,0 +1,18 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class Number + def invalid_params(attributes, generator) + ["0.1", "10", "hoge"] + end + + def valid_param(attributes, generator) + rand + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/primitive_type/object.rb b/lib/fuzz/json/generator/primitive_type/object.rb new file mode 100644 index 0000000..03eb5ef --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/object.rb @@ -0,0 +1,42 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class Object + def invalid_params(attributes, generator) + generated_params = [] + + if (attributes.key?("members") || attributes.key?("properties")) + properties = attributes["members"] || attributes["properties"] + properties.each do |key, attribute| + generator.generate(attribute).each do |invalid_param| + template = generator.default_param(attributes) + generated_params.push(template.merge(key => invalid_param)) + end + end + else + generated_params = [nil, []] + end + + generated_params + end + + def valid_param(attributes, generator) + generated_param = {} + + if (attributes.key?("members") || attributes.key?("properties")) + properties = attributes["members"] || attributes["properties"] + + properties.each do |key, attribute| + generated_param[key] = generator.default_param(attribute) + end + end + + generated_param + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/primitive_type/string.rb b/lib/fuzz/json/generator/primitive_type/string.rb new file mode 100644 index 0000000..df39eaa --- /dev/null +++ b/lib/fuzz/json/generator/primitive_type/string.rb @@ -0,0 +1,18 @@ +module Fuzz + module JSON + class Generator + class PrimitiveType + class String + def invalid_params(attributes, generator) + [1] + end + + def valid_param(attributes, generator) + "hoge" + end + end + end + end + end +end + diff --git a/lib/fuzz/json/generator/type.rb b/lib/fuzz/json/generator/type.rb index a48a9f1..185ff0d 100644 --- a/lib/fuzz/json/generator/type.rb +++ b/lib/fuzz/json/generator/type.rb @@ -6,11 +6,19 @@ def generate(properties, generator) attribute = properties["type"] case attribute when "object" - nil + [nil, []] when "integer" ["1", "a"] when "string" [1] + when "array" + {} + when "boolean" + ["true", "false", "1", "0"] + when "number" + ["0.1", "10", "hoge"] + when "null" + ["nil", "0", "null", false, ""] else warn "not impremented attribute: #{attribute}" end diff --git a/spec/fuzz/json/schema_spec.rb b/spec/fuzz/json/schema_spec.rb index 02bfccc..16556f3 100644 --- a/spec/fuzz/json/schema_spec.rb +++ b/spec/fuzz/json/schema_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require "spec_helper" describe Fuzz::JSON do context "basic features" do - it "integer works" do + it "works" do schema_file = File.join(SPEC_SCHEMA_ROOT, "basic_schema.json") fuzz_params_list = Fuzz::JSON::Generator.generate(schema_file) @@ -13,4 +13,20 @@ end end end + + context "primitive types" do + it "works" do + schema_file = File.join(SPEC_SCHEMA_ROOT, "primitive_types.json") + generator = Fuzz::JSON::Generator.new + default_param = generator.default_param(schema_file) + fuzz_params_list = generator.generate(schema_file) + + fuzz_params_list.each do |params| + expect(params).to include(*default_param.keys) + warn params + result = JSON::Validator.validate(schema_file, params) + expect(result).to eq(false) + end + end + end end diff --git a/spec/schemas/primitive_types.json b/spec/schemas/primitive_types.json new file mode 100644 index 0000000..1019375 --- /dev/null +++ b/spec/schemas/primitive_types.json @@ -0,0 +1,35 @@ +{ + "title": "Primitive Types Schema", + "type": "object", + "properties": { + "arrayKey": { + "type": "array" + }, + "booleanKey": { + "type": "boolean" + }, + "integerKey": { + "type": "integer" + }, + "numberKey": { + "type": "number" + }, + "nullKey": { + "type": "null" + }, + "objectKey": { + "type": "object", + "properties": { + "nested_string": { + "type": "string" + }, + "nested_integer": { + "type": "integer" + } + } + }, + "stringKey": { + "type": "string" + } + } +} From dca87f32c388e0e8b1ab10479d9a294a770bc5b2 Mon Sep 17 00:00:00 2001 From: Naoki Shimizu Date: Thu, 7 Aug 2014 09:45:35 +0900 Subject: [PATCH 5/5] clean up --- lib/fuzz/json/generator/minimum.rb | 19 --------------- lib/fuzz/json/generator/primitive_type.rb | 10 ++++++++ lib/fuzz/json/generator/propaties.rb | 25 ------------------- lib/fuzz/json/generator/type.rb | 29 ----------------------- 4 files changed, 10 insertions(+), 73 deletions(-) delete mode 100644 lib/fuzz/json/generator/minimum.rb delete mode 100644 lib/fuzz/json/generator/propaties.rb delete mode 100644 lib/fuzz/json/generator/type.rb diff --git a/lib/fuzz/json/generator/minimum.rb b/lib/fuzz/json/generator/minimum.rb deleted file mode 100644 index 4dea5fd..0000000 --- a/lib/fuzz/json/generator/minimum.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Fuzz - module JSON - class Generator - class MinimumAttribute - def generate(properties, generator) - type = properties["type"] - minimum_value = properties["minimum"] - - case type - when "integer" - [minimum_value - 1] - else - warn "not impremented type: #{type}" - end - end - end - end - end -end diff --git a/lib/fuzz/json/generator/primitive_type.rb b/lib/fuzz/json/generator/primitive_type.rb index 1538c44..e1cb75d 100644 --- a/lib/fuzz/json/generator/primitive_type.rb +++ b/lib/fuzz/json/generator/primitive_type.rb @@ -1 +1,11 @@ Dir[File.join(File.dirname(__FILE__), "primitive_type/*.rb")].each {|file| require file } + +module Fuzz + module JSON + class Generator + class PrimitiveType + end + end + end +end + diff --git a/lib/fuzz/json/generator/propaties.rb b/lib/fuzz/json/generator/propaties.rb deleted file mode 100644 index f6ae48e..0000000 --- a/lib/fuzz/json/generator/propaties.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Fuzz - module JSON - class Generator - class PropertiesAttribute - def generate(attributes, generator) - generated_params = [] - attribute = attributes["properties"] - - attribute.each do |key, properties| - properties.each do |property_name, property| - if generator.generators.key?(property_name) - invalid_params = generator.generators[property_name].generate(properties, generator) - if invalid_params - invalid_params.each { |param| generated_params.push( {key => param} ) } - end - end - end - end - - generated_params - end - end - end - end -end diff --git a/lib/fuzz/json/generator/type.rb b/lib/fuzz/json/generator/type.rb deleted file mode 100644 index 185ff0d..0000000 --- a/lib/fuzz/json/generator/type.rb +++ /dev/null @@ -1,29 +0,0 @@ -module Fuzz - module JSON - class Generator - class TypeAttribute - def generate(properties, generator) - attribute = properties["type"] - case attribute - when "object" - [nil, []] - when "integer" - ["1", "a"] - when "string" - [1] - when "array" - {} - when "boolean" - ["true", "false", "1", "0"] - when "number" - ["0.1", "10", "hoge"] - when "null" - ["nil", "0", "null", false, ""] - else - warn "not impremented attribute: #{attribute}" - end - end - end - end - end -end