json_schema_power_validator 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/README.md +33 -46
- data/lib/json_schema_power_validator.rb +18 -0
- data/lib/json_schema_power_validator/errors/parse_suite_error.rb +4 -0
- data/lib/json_schema_power_validator/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 217f235573a81f3d22ebb64633f775e1fbe3a9f9
|
4
|
+
data.tar.gz: a0b7ac78f8beac81d279b74729b555299c279bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260a86c6ffa094e83778a21349db4697f55d942b6954dda5e3bcc9b7f1cb03fc1e445e3aa9656d36ebd05940b6cae6805e5af5f56f13289c5fa9179f6fda2641
|
7
|
+
data.tar.gz: fd07b1aa717066dba3b93fb87220e01b3634c957e8ed236f84a860eab3ab6fefebb6417139c97a7759f35f63c56f90928a8ad7a20d37ed015550718d447d884d
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# JsonSchema::PowerValidator
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Test JSON Schema itself with contexts.
|
4
|
+
After preparation of schema and test suite, you can test schema response.
|
5
|
+
It'll display each results with json format.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,62 +22,39 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
```
|
25
|
+
Prepare json schema you'd like to test and test suite.
|
26
|
+
A test suite must be written on the fixed format.
|
27
|
+
The suite must include parameters:
|
28
|
+
|
29
|
+
- examples - Array of test cases, and each of them should include following parameters
|
30
|
+
- context - Title of each test
|
31
|
+
- description - Detail of the test
|
32
|
+
- expect - Expectation of a result of test (it must be "valid"/"invalid")
|
33
|
+
- values - Parameters that'll be used as test values.
|
34
|
+
|
35
|
+
The below json is the example of test suite on the above format.
|
52
36
|
|
53
37
|
```json
|
54
38
|
{
|
55
|
-
"id": "https://github.com/timakin/json_schema_power_validator/schema/suite/sample.json",
|
56
|
-
"description": "Schema PowerValidator for example.json",
|
57
39
|
"examples": [
|
58
40
|
{
|
59
41
|
"context": "Success",
|
60
42
|
"description": "Success Case",
|
61
43
|
"expect": "valid",
|
62
44
|
"values": {
|
63
|
-
|
64
|
-
|
45
|
+
"id": 1234,
|
46
|
+
"name": "timakin",
|
47
|
+
...
|
65
48
|
}
|
66
49
|
},
|
67
50
|
{ ... },
|
68
|
-
{
|
69
|
-
"context": "Fail",
|
70
|
-
"description": "fail",
|
71
|
-
"expect": "valid",
|
72
|
-
"values": {
|
73
|
-
"id": -100,
|
74
|
-
"username": "tim"
|
75
|
-
}
|
76
|
-
}
|
51
|
+
{ ... }
|
77
52
|
]
|
78
53
|
}
|
79
54
|
```
|
80
55
|
|
56
|
+
With the suite, you can get a detail error message, and check whether the results are all clear or not.
|
57
|
+
|
81
58
|
```ruby
|
82
59
|
require 'json_schema_power_validator'
|
83
60
|
|
@@ -90,11 +67,11 @@ validated_schema.get_result
|
|
90
67
|
# "description": "Success Case",
|
91
68
|
# "result": "success"
|
92
69
|
# },
|
93
|
-
# { ... }
|
70
|
+
# { ... },
|
94
71
|
# {
|
95
72
|
# "context": "Fail",
|
96
|
-
# "description": "
|
97
|
-
# "
|
73
|
+
# "description": "Failed Case",
|
74
|
+
# "result": "The property '#/id' did not have a minimum value of 0, inclusively"
|
98
75
|
# }
|
99
76
|
# ]
|
100
77
|
#}
|
@@ -109,6 +86,16 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
109
86
|
|
110
87
|
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).
|
111
88
|
|
89
|
+
## Test
|
90
|
+
|
91
|
+
To run test:
|
92
|
+
|
93
|
+
```
|
94
|
+
$ cd /path/to/repository
|
95
|
+
$ bundle install --path vendor/bundle
|
96
|
+
$ bundle exec ruby spec/json_schema_power_validator_spec.rb
|
97
|
+
```
|
98
|
+
|
112
99
|
## Contributing
|
113
100
|
|
114
101
|
1. Fork it ( https://github.com/timakin/json_schema_power_validator/fork )
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "json_schema_power_validator/version"
|
2
|
+
require "json_schema_power_validator/errors/parse_suite_error"
|
2
3
|
require "json-schema"
|
3
4
|
|
4
5
|
module JsonSchema
|
@@ -22,6 +23,8 @@ module JsonSchema
|
|
22
23
|
private
|
23
24
|
|
24
25
|
def validate
|
26
|
+
verify_suite_parameters
|
27
|
+
|
25
28
|
@suites["examples"].each do |suite|
|
26
29
|
begin
|
27
30
|
JSON::Validator.validate!(@schema, suite["values"])
|
@@ -30,9 +33,24 @@ module JsonSchema
|
|
30
33
|
suite["expect"] == "invalid" ? @raw_results.push("Success") : @raw_results.push($!.message)
|
31
34
|
end
|
32
35
|
end
|
36
|
+
|
33
37
|
get_result_by_json
|
34
38
|
end
|
35
39
|
|
40
|
+
def verify_suite_parameters
|
41
|
+
unless @suites["examples"]
|
42
|
+
raise ParseSuiteError.new("examples for a test suite is undefined, or format is invalid.")
|
43
|
+
end
|
44
|
+
|
45
|
+
@suites["examples"].each do |suite|
|
46
|
+
["context", "description", "expect", "values"].each do |param|
|
47
|
+
if suite[param].nil?
|
48
|
+
raise ParseSuiteError.new("#{param} for a test suite is undefined.")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
36
54
|
def get_result_by_json
|
37
55
|
@raw_results.each_with_index { |result, index|
|
38
56
|
@result_json << {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema_power_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- timakin
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- bin/setup
|
69
69
|
- json_schema_power_validator.gemspec
|
70
70
|
- lib/json_schema_power_validator.rb
|
71
|
+
- lib/json_schema_power_validator/errors/parse_suite_error.rb
|
71
72
|
- lib/json_schema_power_validator/version.rb
|
72
73
|
homepage: https://github.com/timakin/json_schema_power_validator
|
73
74
|
licenses:
|