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

Version Path
solara-0.7.4 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.7.3 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.7.2 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.7.1 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.7.0 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.6.0 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.5.0 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.4.0 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.3.0 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.2.4 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.2.3 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.2.2 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.2.1 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.2.0 solara/lib/core/doctor/validator/json_schema_validator.rb
solara-0.1.0 solara/lib/core/doctor/validator/json_schema_validator.rb