Sha256: f792273d3a6cf4e114dd28615011046221a53622d5a576bdcaa86ee2bd1d3547
Contents?: true
Size: 937 Bytes
Versions: 15
Compression:
Stored size: 937 Bytes
Contents
Dir.glob("#{__dir__}/*.rb").each { |file| require file } require 'json' require 'json-schema' class JsonSchemaValidator < ValidationStrategy def initialize(schema_file, json_file) @schema_file = schema_file @json_file = json_file end def validate(project_path = nil) unless File.exist?(@schema_file) raise ValidationError, "Schema file not found: #{@schema_file}" end begin json_content = JSON.parse(File.read(@json_file)) rescue # Ignore as it's not its responsibility return end schema = JSON.parse(File.read(@schema_file)) errors = JSON::Validator.fully_validate(schema, json_content) if errors.empty? Solara.logger.passed("Valid according to schema: #{@json_file}") else raise ValidationError, "#{@json_file}: #{errors.join(', ')}." end end end
Version data entries
15 entries across 15 versions & 1 rubygems