json_schema 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/json_schema.rb +2 -12
- data/test/json_schema/validator_test.rb +3 -1
- data/test/json_schema_test.rb +0 -21
- metadata +1 -1
data/lib/json_schema.rb
CHANGED
@@ -9,23 +9,13 @@ module JsonSchema
|
|
9
9
|
def self.parse(data)
|
10
10
|
parser = Parser.new
|
11
11
|
if schema = parser.parse(data)
|
12
|
-
|
13
|
-
if valid
|
14
|
-
[schema, nil]
|
15
|
-
else
|
16
|
-
[nil, errors]
|
17
|
-
end
|
12
|
+
[schema, nil]
|
18
13
|
else
|
19
14
|
[nil, parser.errors]
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
18
|
def self.parse!(data)
|
24
|
-
|
25
|
-
schema.expand_references!
|
26
|
-
schema
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.validate(schema, data)
|
19
|
+
Parser.new.parse!(data)
|
30
20
|
end
|
31
21
|
end
|
@@ -666,7 +666,9 @@ describe JsonSchema::Validator do
|
|
666
666
|
end
|
667
667
|
|
668
668
|
def validate
|
669
|
-
@schema = JsonSchema.parse!(schema_sample)
|
669
|
+
@schema = JsonSchema.parse!(schema_sample)
|
670
|
+
@schema.expand_references!
|
671
|
+
@schema = @schema.definitions["app"]
|
670
672
|
@validator = JsonSchema::Validator.new(@schema)
|
671
673
|
@validator.validate(data_sample)
|
672
674
|
end
|
data/test/json_schema_test.rb
CHANGED
@@ -18,16 +18,6 @@ describe JsonSchema do
|
|
18
18
|
assert_includes errors.map { |e| e.message },
|
19
19
|
%{Expected schema; value was: 4.}
|
20
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
21
|
end
|
32
22
|
|
33
23
|
describe ".parse!" do
|
@@ -44,17 +34,6 @@ describe JsonSchema do
|
|
44
34
|
end
|
45
35
|
assert_includes e.message, %{Expected schema; value was: 4.}
|
46
36
|
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
37
|
end
|
59
38
|
|
60
39
|
def pointer(path)
|