json_schema_power_validator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +119 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/json_schema_spec.gemspec +32 -0
- data/lib/json_schema_power_validator/version.rb +3 -0
- data/lib/json_schema_power_validator.rb +47 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 104009841ae93f951d284ab087d5ea5db299fe07
|
4
|
+
data.tar.gz: b82b77bc1871a147a6f781c6165d8a2aa1a58c17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f27e883f0c380629525fe9daba9193795f333be02cfbc546c10b4d384f190b036f71152f495e61c3083a0bd42457534e92954ad46e422582cf391566448f2f74
|
7
|
+
data.tar.gz: 8b4771bf56788d4f69588c3a49a369f3232ff0e9fd172ad99942a1c1f9f11f4fa49470144ca030044d431eabbcf2291e327086de9bea7fed957de32f1f0a5635
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# JsonSchema::PowerValidator
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/json_schema_power_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'json_schema_power_validator'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install json_schema_power_validator
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```json
|
26
|
+
{
|
27
|
+
"id": "https://github.com/timakin/json_schema_power_validator/schema/sample.json",
|
28
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
29
|
+
"description": "Test schema for example",
|
30
|
+
"definitions": {
|
31
|
+
"positiveInt": {
|
32
|
+
"type": "integer",
|
33
|
+
"minimum": 0
|
34
|
+
},
|
35
|
+
"name": {
|
36
|
+
"type": "string",
|
37
|
+
"minimumLength": 4,
|
38
|
+
"maximumLength": 12
|
39
|
+
}
|
40
|
+
},
|
41
|
+
"type": "object",
|
42
|
+
"properties": {
|
43
|
+
"id": {
|
44
|
+
"$ref": "#/definitions/positiveInt"
|
45
|
+
},
|
46
|
+
"username": {
|
47
|
+
"$ref": "#/definitions/name"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
```json
|
54
|
+
{
|
55
|
+
"id": "https://github.com/timakin/json_schema_power_validator/schema/suite/sample.json",
|
56
|
+
"description": "Schema PowerValidator for example.json",
|
57
|
+
"examples": [
|
58
|
+
{
|
59
|
+
"context": "Success",
|
60
|
+
"description": "Success Case",
|
61
|
+
"expect": "valid",
|
62
|
+
"values": {
|
63
|
+
"id": 1,
|
64
|
+
"username": "timakin"
|
65
|
+
}
|
66
|
+
},
|
67
|
+
{ ... },
|
68
|
+
{
|
69
|
+
"context": "Fail",
|
70
|
+
"description": "fail",
|
71
|
+
"expect": "valid",
|
72
|
+
"values": {
|
73
|
+
"id": -100,
|
74
|
+
"username": "tim"
|
75
|
+
}
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
```
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require 'json_schema_power_validator'
|
83
|
+
|
84
|
+
validated_schema = JsonSchema::PowerValidator.new("schema/sample.json", "schema/suite/sample.json")
|
85
|
+
validated_schema.get_result
|
86
|
+
#{
|
87
|
+
# "results": [
|
88
|
+
# {
|
89
|
+
# "context": "Success",
|
90
|
+
# "description": "Success Case",
|
91
|
+
# "result": "success"
|
92
|
+
# },
|
93
|
+
# { ... }
|
94
|
+
# {
|
95
|
+
# "context": "Fail",
|
96
|
+
# "description": "fail"
|
97
|
+
# "result": "fail",
|
98
|
+
# "reason": "Invalid parameter: id should satisfy the condition minimumLength"
|
99
|
+
# }
|
100
|
+
# ]
|
101
|
+
#}
|
102
|
+
|
103
|
+
validated_schema.ok?
|
104
|
+
# false
|
105
|
+
```
|
106
|
+
|
107
|
+
## Development
|
108
|
+
|
109
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
110
|
+
|
111
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
1. Fork it ( https://github.com/timakin/json_schema_power_validator/fork )
|
116
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json_schema_spec"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'json_schema_power_validator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "json_schema_power_validator"
|
8
|
+
spec.version = JsonSchema::VERSION
|
9
|
+
spec.authors = ["timakin"]
|
10
|
+
spec.email = ["timaki.st@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby-based Power validator for JSON Schema}
|
13
|
+
spec.description = %q{Test JSON Schema itself with JSON Schema and a little ruby code.}
|
14
|
+
spec.homepage = "https://github.com/timakin/json_schema_power_validator"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "json-schema", "~> 2.5.1"
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "json_schema_power_validator/version"
|
2
|
+
require "json-schema"
|
3
|
+
|
4
|
+
module JsonSchema
|
5
|
+
class PowerValidator
|
6
|
+
def initialize(schema, suite)
|
7
|
+
@schema = JSON.parse(File.read(schema))
|
8
|
+
@suites = JSON.parse(File.read(suite))
|
9
|
+
@raw_results ||= []
|
10
|
+
@result_json ||= []
|
11
|
+
@results = validate
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_result
|
15
|
+
JSON.pretty_generate(@results)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ok?
|
19
|
+
@raw_results.all? { |result| result == "Success" }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate
|
25
|
+
@suites["examples"].each do |suite|
|
26
|
+
begin
|
27
|
+
JSON::Validator.validate!(@schema, suite["values"])
|
28
|
+
@raw_results.push("Success")
|
29
|
+
rescue JSON::Schema::ValidationError
|
30
|
+
suite["expect"] == "invalid" ? @raw_results.push("Success") : @raw_results.push($!.message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
get_result_by_json
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_result_by_json
|
37
|
+
@raw_results.each_with_index { |result, index|
|
38
|
+
@result_json << {
|
39
|
+
context: @suites["examples"][index]["context"],
|
40
|
+
description: @suites["examples"][index]["description"],
|
41
|
+
result: result
|
42
|
+
}
|
43
|
+
}
|
44
|
+
{results: @result_json}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_schema_power_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- timakin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json-schema
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.5.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.5.1
|
55
|
+
description: Test JSON Schema itself with JSON Schema and a little ruby code.
|
56
|
+
email:
|
57
|
+
- timaki.st@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- json_schema_spec.gemspec
|
70
|
+
- lib/json_schema_power_validator.rb
|
71
|
+
- lib/json_schema_power_validator/version.rb
|
72
|
+
homepage: https://github.com/timakin/json_schema_power_validator
|
73
|
+
licenses: []
|
74
|
+
metadata:
|
75
|
+
allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ruby-based Power validator for JSON Schema
|
96
|
+
test_files: []
|