json_schema 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -0
- data/lib/json_pointer.rb +7 -0
- data/lib/json_pointer/evaluator.rb +75 -0
- data/lib/json_reference.rb +39 -0
- data/lib/json_schema.rb +27 -0
- data/lib/json_schema/parser.rb +296 -0
- data/lib/json_schema/reference_expander.rb +156 -0
- data/lib/json_schema/schema.rb +155 -0
- data/lib/json_schema/schema_error.rb +25 -0
- data/lib/json_schema/validator.rb +405 -0
- data/test/data_scaffold.rb +238 -0
- data/test/json_pointer/evaluator_test.rb +60 -0
- data/test/json_schema/parser_test.rb +230 -0
- data/test/json_schema/reference_expander_test.rb +149 -0
- data/test/json_schema/validator_test.rb +606 -0
- data/test/json_schema_test.rb +67 -0
- data/test/test_helper.rb +4 -0
- metadata +64 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
require "json_schema"
|
4
|
+
|
5
|
+
describe JsonSchema do
|
6
|
+
describe ".parse" do
|
7
|
+
it "succeeds" do
|
8
|
+
schema, errors = JsonSchema.parse(schema_sample)
|
9
|
+
assert schema
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns errors on a parsing problem" do
|
13
|
+
pointer("#/properties").merge!(
|
14
|
+
"app" => 4
|
15
|
+
)
|
16
|
+
schema, errors = JsonSchema.parse(schema_sample)
|
17
|
+
refute schema
|
18
|
+
assert_includes errors.map { |e| e.message },
|
19
|
+
%{Expected schema; value was: 4.}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns errors on a reference expansion problem" do
|
23
|
+
pointer("#/properties").merge!(
|
24
|
+
"app" => { "$ref" => "#/bad-json-reference" }
|
25
|
+
)
|
26
|
+
schema, errors = JsonSchema.parse(schema_sample)
|
27
|
+
refute schema
|
28
|
+
assert_includes errors.map { |e| e.message },
|
29
|
+
%{Couldn't resolve pointer "#/bad-json-reference".}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".parse!" do
|
34
|
+
it "succeeds on .parse!" do
|
35
|
+
assert JsonSchema.parse!(schema_sample)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns errors on a parsing problem" do
|
39
|
+
pointer("#/properties").merge!(
|
40
|
+
"app" => 4
|
41
|
+
)
|
42
|
+
e = assert_raises(RuntimeError) do
|
43
|
+
JsonSchema.parse!(schema_sample)
|
44
|
+
end
|
45
|
+
assert_includes e.message, %{Expected schema; value was: 4.}
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns errors on a reference expansion problem" do
|
49
|
+
pointer("#/properties").merge!(
|
50
|
+
"app" => { "$ref" => "#/bad-json-reference" }
|
51
|
+
)
|
52
|
+
e = assert_raises(RuntimeError) do
|
53
|
+
JsonSchema.parse!(schema_sample)
|
54
|
+
end
|
55
|
+
assert_includes e.message,
|
56
|
+
%{Couldn't resolve pointer "#/bad-json-reference".}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def pointer(path)
|
61
|
+
JsonPointer.evaluate(schema_sample, path)
|
62
|
+
end
|
63
|
+
|
64
|
+
def schema_sample
|
65
|
+
@schema_sample ||= DataScaffold.schema_sample
|
66
|
+
end
|
67
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_schema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brandur
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- brandur@mutelight.org
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- lib/json_pointer/evaluator.rb
|
23
|
+
- lib/json_pointer.rb
|
24
|
+
- lib/json_reference.rb
|
25
|
+
- lib/json_schema/parser.rb
|
26
|
+
- lib/json_schema/reference_expander.rb
|
27
|
+
- lib/json_schema/schema.rb
|
28
|
+
- lib/json_schema/schema_error.rb
|
29
|
+
- lib/json_schema/validator.rb
|
30
|
+
- lib/json_schema.rb
|
31
|
+
- test/data_scaffold.rb
|
32
|
+
- test/json_pointer/evaluator_test.rb
|
33
|
+
- test/json_schema/parser_test.rb
|
34
|
+
- test/json_schema/reference_expander_test.rb
|
35
|
+
- test/json_schema/validator_test.rb
|
36
|
+
- test/json_schema_test.rb
|
37
|
+
- test/test_helper.rb
|
38
|
+
homepage: https://github.com/brandur/json_schema
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.24
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: A JSON Schema V4 and Hyperschema V4 parser and validator.
|
63
|
+
test_files: []
|
64
|
+
has_rdoc:
|