File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,24 @@ def validation_failure_message
19
19
errors . first . to_s
20
20
end
21
21
22
+ class << self
23
+ attr_writer :document_store
24
+
25
+ def document_store
26
+ @document_store ||= begin
27
+ document_store = JsonSchema ::DocumentStore . new
28
+
29
+ Dir . glob ( "#{ JsonMatchers . schema_root } /**/*.json" ) .
30
+ map { |path | Pathname . new ( path ) } .
31
+ map { |schema_path | Parser . new ( schema_path ) . parse } .
32
+ map { |schema | document_store . add_schema ( schema ) } .
33
+ each { |schema | schema . expand_references! ( store : document_store ) }
34
+
35
+ document_store
36
+ end
37
+ end
38
+ end
39
+
22
40
private
23
41
24
42
attr_accessor :errors
@@ -29,15 +47,7 @@ def validator
29
47
end
30
48
31
49
def build_and_populate_document_store
32
- document_store = JsonSchema ::DocumentStore . new
33
-
34
- Dir . glob ( "#{ JsonMatchers . schema_root } /**/*.json" ) .
35
- map { |path | Pathname . new ( path ) } .
36
- map { |schema_path | Parser . new ( schema_path ) . parse } .
37
- map { |schema | document_store . add_schema ( schema ) } .
38
- each { |schema | schema . expand_references! ( store : document_store ) }
39
-
40
- document_store
50
+ self . class . document_store
41
51
end
42
52
end
43
53
end
Original file line number Diff line number Diff line change 59
59
expect ( json ) . to match_json_schema ( "api/v1/schema" )
60
60
end
61
61
62
+ it "does not reload document store" do
63
+ create ( :schema , :location , name : "api/v1/schema" )
64
+
65
+ json = build ( :response , :location )
66
+
67
+ expect ( Dir ) . to receive ( :glob ) . once . and_call_original
68
+ 2 . times do
69
+ expect ( json ) . to match_json_schema ( "api/v1/schema" )
70
+ end
71
+ end
72
+
62
73
it "supports invalidating the referenced schema when using local references" do
63
74
create ( :schema , name : "post" , json : {
64
75
"$schema" : "https://json-schema.org/draft-04/schema#" ,
You can’t perform that action at this time.
0 commit comments