Sha256: bac87d72cb56806f7237485df3f49168203ec479798bf576451006a7bab547af

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module JSON
  class Schema
    class PropertiesV4Attribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        if data.is_a?(Hash)
          current_schema.schema['properties'].each do |property,property_schema|
            if !data.has_key?(property.to_s) &&
               !data.has_key?(property.to_sym) &&
               property_schema['default'] &&
               !property_schema['readonly'] &&
               options[:insert_defaults]
              default = property_schema['default']
              data[property.to_s] = (default.is_a?(Hash) ? default.clone : default)
            end

            if data.has_key?(property.to_s) || data.has_key?(property.to_sym)
              schema = JSON::Schema.new(property_schema,current_schema.uri,validator)
              fragments << property.to_s
              schema.validate(data[property.to_s],fragments,processor,options)
              fragments.pop
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
json-schema-2.1.9 lib/json-schema/attributes/properties_v4.rb
json-schema-2.1.8 lib/json-schema/attributes/properties_v4.rb
json-schema-2.1.7 lib/json-schema/attributes/properties_v4.rb
json-schema-2.1.6 lib/json-schema/attributes/properties_v4.rb