Sha256: b7211e2f2edf3fdd08c21f47b43f505339c88bc48ef7082bf556befc4e8b00c8

Contents?: true

Size: 1.8 KB

Versions: 20

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module JSI
  module Schema::Validation::MinMaxProperties
    # @private
    def internal_validate_maxProperties(result_builder)
      if keyword?('maxProperties')
        value = schema_content['maxProperties']
        # The value of this keyword MUST be a non-negative integer.
        if internal_integer?(value) && value >= 0
          if result_builder.instance.respond_to?(:to_hash)
            # An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
            result_builder.validate(
              result_builder.instance.size <= value,
              'instance object contains more properties than `maxProperties` value',
              keyword: 'maxProperties',
            )
          end
        else
          result_builder.schema_error('`maxProperties` is not a non-negative integer', 'maxProperties')
        end
      end
    end

    # @private
    def internal_validate_minProperties(result_builder)
      if keyword?('minProperties')
        value = schema_content['minProperties']
        # The value of this keyword MUST be a non-negative integer.
        if internal_integer?(value) && value >= 0
          if result_builder.instance.respond_to?(:to_hash)
            # An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.
            result_builder.validate(
              result_builder.instance.size >= value,
              'instance object contains fewer properties than `minProperties` value',
              keyword: 'minProperties',
            )
          end
        else
          result_builder.schema_error('`minProperties` is not a non-negative integer', 'minProperties')
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
jsi-0.8.1 lib/jsi/schema/validation/object.rb
jsi-0.8.0 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.4 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.5 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.6 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.7 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.8 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.8.pre.maruku lib/jsi/schema/validation/object.rb
jsi-dev-0.0.7.pre.rdiscount lib/jsi/schema/validation/object.rb
jsi-dev-0.0.6.pre.redcarpet lib/jsi/schema/validation/object.rb
jsi-dev-0.0.5.pre.kramdown lib/jsi/schema/validation/object.rb
jsi-dev-0.0.4.pre.commonmarker lib/jsi/schema/validation/object.rb
jsi-dev-0.0.0.pre.commonmarker lib/jsi/schema/validation/object.rb
jsi-dev-0.0.0.pre.kramdown lib/jsi/schema/validation/object.rb
jsi-dev-0.0.0.pre.redcarpet lib/jsi/schema/validation/object.rb
jsi-dev-0.0.0.pre.rdiscount lib/jsi/schema/validation/object.rb
jsi-dev-0.0.0.pre.maruku lib/jsi/schema/validation/object.rb
jsi-dev-0.0.3 lib/jsi/schema/validation/object.rb
jsi-dev-0.0.2 lib/jsi/schema/validation/object.rb
jsi-0.7.0 lib/jsi/schema/validation/object.rb