Skip to content

Commit d611009

Browse files
authored
Merge pull request #375 from iainbeeston/update-metaschema-rake-task
Added a rake task to automatically download the latest metaschemas
2 parents 3c00613 + ff08e1a commit d611009

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,11 +19,50 @@ 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
t.warning = true
2562
t.verbose = true
2663
t.test_files = FileList.new('test/*_test.rb')
2764
end
2865

66+
task update: [:update_common_tests, :update_meta_schemas]
67+
2968
task :default => :test

0 commit comments

Comments
 (0)