-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlint.rb
More file actions
31 lines (27 loc) · 860 Bytes
/
lint.rb
File metadata and controls
31 lines (27 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'json'
require 'json_schemer'
require 'open-uri'
require 'ruby-progressbar'
def lint(paths, schema_url)
invalid = []
schemer = JSONSchemer.schema JSON.load(URI.open(schema_url))
bar = ProgressBar.create format: "Linting record %c/%C (%P% complete ) — %e", total: paths.length
paths.each do |path|
record = JSON.parse File.read(path)
id = record['layer_id_s'] || record['id']
invalid << {
'id' => id,
'errors' => schemer.validate(record).map { |x| x['error'] }
} unless schemer.valid?(record)
bar.increment
end
if invalid.empty?
puts "All #{paths.length} records passed ✅"
else
puts "#{invalid.length}/#{paths.length} records have failed schema validation:"
invalid.each do |i|
puts "❌ #{i['id']}"
i['errors'].each { |e| puts "\t #{e}" }
end
end
end