Sha256: 08f8224e938471b0af77014c86c0efbb115f8f40176347f460a20a6940701e3d

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class NotAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        schema = JSON::Schema.new(current_schema.schema['not'],current_schema.uri,validator)
        failed = true
        errors_copy = processor.validation_errors.clone

        begin
          schema.validate(data,fragments,processor,options)
          # If we're recording errors, we don't throw an exception. Instead, check the errors array length
          if options[:record_errors] && errors_copy.length != processor.validation_errors.length
            processor.validation_errors.replace(errors_copy)
          else
            message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} matched the disallowed schema"
            failed = false
          end
        rescue ValidationError
          # Yay, we failed validation.
        end

        unless failed
          validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
        end
      end
    end
  end
end

Version data entries

7 entries across 6 versions & 3 rubygems

Version Path
json-schema-ouidou-2.9.1 lib/json-schema/attributes/not.rb
json-schema-ouidou-2.9.0 lib/json-schema/attributes/not.rb
json-schema-3.0.0 lib/json-schema/attributes/not.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/lib/json-schema/attributes/not.rb
mountapi-0.11.1 vendor/json-schema/lib/json-schema/attributes/not.rb
json-schema-2.8.1 lib/json-schema/attributes/not.rb
json-schema-2.8.0 lib/json-schema/attributes/not.rb