Sha256: b04fa6c4364dd4269dc12bb4072260da96d819d941fa58bac165ff1feb0d13b7

Contents?: true

Size: 974 Bytes

Versions: 6

Compression:

Stored size: 974 Bytes

Contents

require "pathname"
require "json_schema_rails/schema_validator"

namespace :schema do
  desc "Check syntax of schema files"
  task :check do
    validator = JsonSchemaRails::SchemaValidator.new.use_core_schemas!

    find_root = defined?(Rails) ? Rails.root : Pathname.pwd
    schema_paths = Dir[
      find_root.join('app', 'schema.*'),
      find_root.join('app', 'schemas', '**', '*.{json,yml,yaml}')
    ]
    if schema_paths.empty?
      puts "No schema files found"
      next
    end

    error_count = 0
    schema_paths.each do |path|
      begin
        validator.validate(path)
      rescue JsonSchemaRails::Error => e
        relpath = Pathname.new(path).relative_path_from(find_root)
        puts "#{relpath}: #{e.message}"
        error_count += 1
      end
    end

    if error_count == 0
      STDERR.puts "All schema files has passed validation!"
    else
      STDERR.puts
      abort "#{error_count} file(s) have failed for validation"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
json_schema_rails-0.2.1 lib/tasks/schema_tasks.rake
json_schema_rails-0.2.0 lib/tasks/schema_tasks.rake
json_schema_rails-0.1.0 lib/tasks/schema_tasks.rake
json_schema_rails-0.0.3 lib/tasks/schema_tasks.rake
json_schema_rails-0.0.2 lib/tasks/schema_tasks.rake
json_schema_rails-0.0.1 lib/tasks/schema_tasks.rake