-
Notifications
You must be signed in to change notification settings - Fork 3
/
validate.rb
50 lines (41 loc) · 1 KB
/
validate.rb
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
require 'json_schemer'
require 'pathname'
@schema = Pathname.new('m3_json_schema.json')
puts "supply the file to validate, eg. ruby validate.rb m3.yml" if ARGV[0].nil?
exit if ARGV[0].nil?
puts "can't fine the file" unless File.exist?(ARGV[0])
exit unless File.exist?(ARGV[0])
@specification = YAML.load_file(ARGV[0])
def load_schema
@schemer = JSONSchemer.schema(@schema)
puts 'Schema valid? true'
true
rescue StandardError => e
puts e.message
puts 'Schema valid? false'
end
def validate!
@schemer.validate(@specification)
end
def valid?
valid = @schemer.valid?(@specification)
puts "Specification valid? #{valid}"
valid
end
if load_schema
result = validate!
result&.to_a&.each do |error|
puts "Data: #{error['data']}"
puts "Data pointer: #{error['data_pointer']}"
puts "Schema: #{error['schema']}"
puts "Schema pointer: #{error['schema_pointer']}"
puts "Type: #{error['type']}"
puts "\n"
end
end
if valid?
exit(true)
else
exit(1)
end