Skip to content

pboling/json_schemer-fuzz

Β 
Β 

Repository files navigation

JSONSchemer::Fuzz

A JSON FUZZ Generator in Ruby from JSON Schema files.

This gem is a re-write & renaming of dead-since-2015 json-fuzz-generator, It has been re-built on top of the modern json_schemer instead of the unmaintained json-schema.

Test Coverage Maintainability Depfu


Liberapay Patrons Sponsor Me on Github Buy me coffee donation button Patreon donate button

Installation

Add this line to your application's Gemfile:

gem 'json_schemer-fuzz'

And then execute:

$ bundle

Or install it yourself as:

$ gem install json_schemer-fuzz

Usage

generate valid param

require "json_schema-fuzz"

json = <<~JSON
  {
    "title": "Basic Schema",
    "type": "object",
    "properties": {
      "id" : {
        "type": "integer",
        "minimum": 0
      },
      "name": {
        "type": "string"
      },
      "birthday": {
        "type": "string",
        "format": "date"
      }
    }
  }
JSON

schema = JSON.parse(json)
JSONSchemer::Fuzz.default_param(schema)
# => {"id"=>0, "name"=>"hoge", "birthday"=>"1992-06-27"}

generate invalid params

require "json_schema-fuzz"

json = <<~JSON
  {
    "title": "Basic Schema",
    "type": "object",
    "properties": {
      "id" : {
        "type": "integer",
        "minimum": 0
      },
      "name": {
        "type": "string"
      },
      "birthday": {
        "type": "string",
        "format": "date"
      }
    }
  }
JSON
schema = JSON.parse(json)
JSONSchemer::Fuzz.generate(schema)
# => [
#       ["sample", "array"],
#       false,
#       83,
#       nil,
#       0.8182545022111043,
#       "hoge",
#       {"id"=>"&", "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>[0.1], "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>["sample", "array"], "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>false, "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>nil, "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>0.0, "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>{}, "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>"hoge", "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>-1, "name"=>"hoge", "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>["sample", "array"], "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>true, "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>30, "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>nil, "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>0.8849255474901346, "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>{}, "birthday"=>"1992-06-27"},
#       {"id"=>0, "name"=>"hoge", "birthday"=>["sample", "array"]},
#       {"id"=>0, "name"=>"hoge", "birthday"=>true},
#       {"id"=>0, "name"=>"hoge", "birthday"=>62},
#       {"id"=>0, "name"=>"hoge", "birthday"=>nil},
#       {"id"=>0, "name"=>"hoge", "birthday"=>0.05006772646327107},
#       {"id"=>0, "name"=>"hoge", "birthday"=>{}},
#       {"id"=>0, "name"=>"hoge", "birthday"=>"2010-01-32"},
#       {"id"=>0, "name"=>"hoge", "birthday"=>"n2010-01-01"},
#       {"id"=>0, "name"=>"hoge", "birthday"=>"2010-1-01"},
#       {"id"=>0, "name"=>"hoge", "birthday"=>"2010-01-1"},
#       {"id"=>0, "name"=>"hoge", "birthday"=>"2010-01-01n"}
#     ]

Development

Run tests!

bundle install
bundle exec rake

Contributing

See CONTRIBUTING.md

πŸͺ‡ Code of Conduct

Everyone interacting in this project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

πŸ“Œ Versioning

This Library adheres to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

To get a better understanding of how SemVer is intended to work over a project's lifetime, read this article from the creator of SemVer:

As a result of this policy, you can (and should) specify a dependency on these libraries using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency("json_schemer-fuzz", "~> 1.0")

πŸ“„ License

The gem is available as open source under the terms of the MIT License License: MIT. See LICENSE.txt for the official Copyright Notice.

Β© Copyright