Skip to content

Commit ff08e1a

Browse files
committed
Added a rake task to automatically download the latest metaschemas
The metaschemas change occasionally. Draft6 is changing all the time as new features are added. So we can keep on top of this, I've added a new rake task which will download all of the latest metaschemas and save them over the existing ones (in the resources directory)
1 parent 9c9719f commit ff08e1a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Rakefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,43 @@ task :update_common_tests do
1919
end
2020
end
2121

22+
desc "Update meta-schemas to the latest version"
23+
task :update_meta_schemas do
24+
puts "Updating meta-schemas..."
25+
26+
id_mappings = {
27+
'http://json-schema.org/draft/schema#' => 'https://raw.githubusercontent.com/json-schema-org/json-schema-spec/master/schema.json'
28+
}
29+
30+
require 'open-uri'
31+
require 'thwait'
32+
33+
download_threads = Dir['resources/*.json'].map do |path|
34+
schema_id = File.read(path)[/"\$?id"\s*:\s*"(.*?)"/, 1]
35+
schema_uri = id_mappings[schema_id] || schema_id
36+
37+
Thread.new(schema_uri) do |uri|
38+
Thread.current[:uri] = uri
39+
40+
begin
41+
metaschema = URI(uri).read
42+
43+
File.write(path, metaschema)
44+
rescue StandardError
45+
false
46+
end
47+
end
48+
end
49+
50+
ThreadsWait.all_waits(*download_threads) do |t|
51+
if t.value
52+
puts t[:uri]
53+
else
54+
STDERR.puts "Failed to update meta-schema #{t[:uri]}"
55+
end
56+
end
57+
end
58+
2259
Rake::TestTask.new do |t|
2360
t.libs << "."
2461
# disabled warnings because addressable 2.4 has lots of them
@@ -27,4 +64,6 @@ Rake::TestTask.new do |t|
2764
t.test_files = FileList.new('test/*_test.rb')
2865
end
2966

67+
task update: [:update_common_tests, :update_meta_schemas]
68+
3069
task :default => :test

0 commit comments

Comments
 (0)