Sha256: ca5322233a39cd4696272faec76a949e04b9f1da6f18b733376fe4045fbeb21b

Contents?: true

Size: 872 Bytes

Versions: 10

Compression:

Stored size: 872 Bytes

Contents

require 'json-schema/attribute'

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

        propnames = current_schema.schema['propertyNames']

        if propnames.is_a?(Hash)
          schema = JSON::Schema.new(propnames, current_schema.uri, validator)
          data.each_key do |key|
            schema.validate(key, fragments + [key], processor, options)
          end
        elsif propnames == false && data.any?
          message = "The property '#{build_fragment(fragments)}' contains additional properties #{data.keys.inspect} outside of the schema when none are allowed"
          validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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