Sha256: ad93051e1d2906ea31d465f4eb6e0625f5efe4f332cc393626dd611069158abd

Contents?: true

Size: 990 Bytes

Versions: 12

Compression:

Stored size: 990 Bytes

Contents

module JSON
  class Schema
    class PropertiesOptionalAttribute < 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 ((property_schema['optional'].nil? || property_schema['optional'] == false) && !data.has_key?(property))
              message = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
              validation_error(processor, 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,processor,options)
              fragments.pop
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
json-schema-1.2.1 lib/json-schema/attributes/properties_optional.rb
json-schema-1.2.0 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.1 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.0 lib/json-schema/attributes/properties_optional.rb
json-schema-2.0.5 lib/json-schema/attributes/properties_optional.rb
json-schema-2.0.4 lib/json-schema/attributes/properties_optional.rb
json-schema-2.0.3 lib/json-schema/attributes/properties_optional.rb
json-schema-2.0.2 lib/json-schema/attributes/properties_optional.rb
json-schema-2.0.1 lib/json-schema/attributes/properties_optional.rb
json-schema-2.0.0 lib/json-schema/attributes/properties_optional.rb
json-schema-1.1.1 lib/json-schema/attributes/properties_optional.rb
json-schema-1.1.0 lib/json-schema/attributes/properties_optional.rb