File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,50 @@ task :update_common_tests do
1919 end
2020end
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+
2259Rake ::TestTask . new do |t |
2360 t . libs << "."
2461 t . warning = true
2562 t . verbose = true
2663 t . test_files = FileList . new ( 'test/*_test.rb' )
2764end
2865
66+ task update : [ :update_common_tests , :update_meta_schemas ]
67+
2968task :default => :test
You can’t perform that action at this time.
0 commit comments