Skip to content

Commit

Permalink
📝 Update usage docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Oct 26, 2023
1 parent 84d993b commit fd62f03
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 73 deletions.
155 changes: 87 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,86 +46,105 @@ Or install it yourself as:

## Usage

### input JSON Schema

```json:input_schema.json
{
"title": "Basic Schema",
"type": "object",
"properties": {
"id" : {
"type": "integer",
"minimum": 0
},
"name": {
"type": "string"
},
"birthday": {
"type": "string",
"format": "date"
}
}
}
```
### generate valid param

```#<--rubocop/md-->ruby
require "json-fuzz-generator"
```ruby
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

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

### generate invalid params

```#<--rubocop/md-->ruby
require "json-fuzz-generator"
JSONSchemer::Fuzz.generate(schema_file)
# =>
#[
# ["sample", "array"],
# true,
# 73,
# nil,
# 0.34259093948835795,
# "hoge",
# {"id"=>"a", "name"=>"hoge", "birthday"=>"1992-06-27"},
# {"id"=>"1", "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"=>97, "birthday"=>"1992-06-27"},
# {"id"=>0, "name"=>nil, "birthday"=>"1992-06-27"},
# {"id"=>0, "name"=>0.7547537108664406, "birthday"=>"1992-06-27"},
# {"id"=>0, "name"=>{}, "birthday"=>"1992-06-27"},
# {"id"=>0, "name"=>"hoge", "birthday"=>["sample", "array"]},
# {"id"=>0, "name"=>"hoge", "birthday"=>false},
# {"id"=>0, "name"=>"hoge", "birthday"=>11},
# {"id"=>0, "name"=>"hoge", "birthday"=>nil},
# {"id"=>0, "name"=>"hoge", "birthday"=>0.5380909041403419},
# {"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"},
#]
```ruby
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!

```#<--rubocop/md-->shell
```shell
bundle install
bundle exec rspec spec
bundle exec rake
```

## Contributing
Expand Down Expand Up @@ -159,8 +178,8 @@ the [Pessimistic Version Constraint][📌pvc] with two digits of precision.

For example:

```#<--rubocop/md-->ruby
spec.add_dependency "json_schemer-fuzz", "~> 1.0"
```ruby
spec.add_dependency("json_schemer-fuzz", "~> 1.0")
```

[comment]: <> ( VERSIONING LINKS )
Expand Down
10 changes: 5 additions & 5 deletions bin/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ m = Module.new do
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/o
bundler_version = $1
update_index = i
end
Expand All @@ -56,7 +56,7 @@ m = Module.new do
def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/o
Regexp.last_match(1)
end

Expand All @@ -83,15 +83,15 @@ m = Module.new do

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
gem("bundler", bundler_requirement)
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
warn("Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`")
exit(42)
end

def activation_error_handling
Expand Down

0 comments on commit fd62f03

Please sign in to comment.