Sha256: f79c90486c56151f4bd45de4128548b9cec423aa356f2c0c1666515adb5283b5

Contents?: true

Size: 903 Bytes

Versions: 8

Compression:

Stored size: 903 Bytes

Contents

module JSON
  class Schema
    class PropertiesAttribute < Attribute
      def self.validate(current_schema, data, fragments, validator, options = {})
        if data.is_a?(Hash)
          current_schema.schema['properties'].each do |property,property_schema|
            if (property_schema['required'] && !data.has_key?(property))
              message = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
              validation_error(message, fragments, current_schema, self, options[:record_errors])
            end
          
            if data.has_key?(property)
              schema = JSON::Schema.new(property_schema,current_schema.uri,validator)
              fragments << property
              schema.validate(data[property],fragments,options)
              fragments.pop
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
json-schema-1.0.11 lib/json-schema/attributes/properties.rb
json-schema-1.0.10 lib/json-schema/attributes/properties.rb
json-schema-1.0.9 lib/json-schema/attributes/properties.rb
json-schema-1.0.8 lib/json-schema/attributes/properties.rb
json-schema-1.0.7 lib/json-schema/attributes/properties.rb
json-schema-1.0.6 lib/json-schema/attributes/properties.rb
json-schema-1.0.5 lib/json-schema/attributes/properties.rb
json-schema-1.0.4 lib/json-schema/attributes/properties.rb