Sha256: 94baeed91153887b52c2b6698f39b92640efa3587e55ac72a5fc1831ec132565

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

module JSON
  class Schema
    class Validator
      attr_accessor :attributes, :formats, :uri, :names
      attr_reader :default_formats

      def initialize()
        @attributes = {}
        @formats = {}
        @default_formats = {}
        @uri = nil
        @names = []
        @metaschema_name = ''
      end

      def extend_schema_definition(schema_uri)
        warn "[DEPRECATION NOTICE] The preferred way to extend a Validator is by subclassing, rather than #extend_schema_definition. This method will be removed in version >= 3."
        validator = JSON::Validator.validator_for_uri(schema_uri)
        @attributes.merge!(validator.attributes)
      end

      def validate(current_schema, data, fragments, processor, options = {})
        current_schema.schema.each do |attr_name,attribute|
          # Added: don't try to validate if
          # - Attribute is false and does not needs to validate anything (eg: uniqueItems) some still needs validation (eg: additionalProperties)
          # - Attribute is nil and it makes crash the validation (eg: divisibleBy). This should fixed on mountapi side
          if @attributes.has_key?(attr_name.to_s) && (attribute != false || @attributes[attr_name.to_s].validate_on_false?) && !attribute.nil?
            @attributes[attr_name.to_s].validate(current_schema, data, fragments, processor, self, options)
          end
        end
        data
      end

      def metaschema
        resources = File.expand_path('../../../../resources', __FILE__)
        File.join(resources, @metaschema_name)
      end
    end
  end
end

Version data entries

4 entries across 3 versions & 2 rubygems

Version Path
json-schema-ouidou-2.9.1 lib/json-schema/schema/validator.rb
json-schema-ouidou-2.9.0 lib/json-schema/schema/validator.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/lib/json-schema/schema/validator.rb
mountapi-0.11.1 vendor/json-schema/lib/json-schema/schema/validator.rb