Sha256: 56980e8847fa0d04e2e7457f803f6877b9e97bfb602b60c696b21de363a0ddab

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

module JSON
  class Schema
    class AllOfAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        # Create an array to hold errors that are generated during validation
        errors = []
        valid = true

        current_schema.schema['allOf'].each do |element|
          schema = JSON::Schema.new(element,current_schema.uri,validator)

          # We're going to add a little cruft here to try and maintain any validation errors that occur in the allOf
          # We'll handle this by keeping an error count before and after validation, extracting those errors and pushing them onto an error array
          pre_validation_error_count = validation_errors(processor).count

          begin
            schema.validate(data,fragments,processor,options)
          rescue ValidationError
            valid = false
          end

          diff = validation_errors(processor).count - pre_validation_error_count
          while diff > 0
            diff = diff - 1
            errors.push(validation_errors(processor).pop)
          end
        end

        if !valid
          message = "The property '#{build_fragment(fragments)}' of type #{data.class} did not match all of the required schemas"
          validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
          validation_errors(processor).last.sub_errors = errors
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
json-schema-2.1.3 lib/json-schema/attributes/allof.rb
json-schema-2.1.2 lib/json-schema/attributes/allof.rb
json-schema-2.1.1 lib/json-schema/attributes/allof.rb
json-schema-2.1.0 lib/json-schema/attributes/allof.rb
json-schema-2.0.5 lib/json-schema/attributes/allof.rb
json-schema-2.0.4 lib/json-schema/attributes/allof.rb
json-schema-2.0.3 lib/json-schema/attributes/allof.rb
json-schema-2.0.2 lib/json-schema/attributes/allof.rb
json-schema-2.0.1 lib/json-schema/attributes/allof.rb
json-schema-2.0.0 lib/json-schema/attributes/allof.rb