Sha256: cb414f8afd5c35a4ac1d256d570ace0a91548e2f1539411d7134c36c8a6966d3

Contents?: true

Size: 742 Bytes

Versions: 8

Compression:

Stored size: 742 Bytes

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class PatternPropertiesAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        return unless data.is_a?(Hash)

        current_schema.schema['patternProperties'].each do |property, property_schema|
          regexp = Regexp.new(property)

          # Check each key in the data hash to see if it matches the regex
          data.each do |key, value|
            next unless regexp.match(key)

            schema = JSON::Schema.new(property_schema, current_schema.uri, validator)
            schema.validate(data[key], fragments + [key], processor, options)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
json-schema-5.0.1 lib/json-schema/attributes/patternproperties.rb
json-schema-5.0.0 lib/json-schema/attributes/patternproperties.rb
json-schema-4.3.1 lib/json-schema/attributes/patternproperties.rb
json-schema-4.3.0 lib/json-schema/attributes/patternproperties.rb
json-schema-4.2.0 lib/json-schema/attributes/patternproperties.rb
json-schema-4.1.1 lib/json-schema/attributes/patternproperties.rb
json-schema-4.1.0 lib/json-schema/attributes/patternproperties.rb
json-schema-4.0.0 lib/json-schema/attributes/patternproperties.rb