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
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/commands/validate_schema.rb', line 23
def run(argv)
return false if !initialize_store
if !detect
return false if !(schema_file = argv.shift)
return false if !(schema = parse(schema_file))
end
return false if argv.count < 1
argv.each do |data_file|
if !(data = read_file(data_file))
return false
end
if detect
if !(schema_uri = data["$schema"])
@errors = ["#{data_file}: No $schema tag for detection."]
return false
end
if !(schema = @store.lookup_schema(schema_uri))
@errors = ["#{data_file}: Unknown $schema, try specifying one with -s."]
return false
end
end
valid, errors = schema.validate(data, fail_fast: fail_fast)
if valid
@messages += ["#{data_file} is valid."]
else
@errors = map_schema_errors(data_file, errors)
end
end
@errors.empty?
end
|