Sha256: 4ff4aef3e0f5b7653ba64b0ef08676e30321840251f94ed61ae2aded25f27f7d

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module JSON
  class Schema
    class DependenciesAttribute < Attribute
      def self.validate(current_schema, data, fragments, validator, options = {})
        if data.is_a?(Hash)
          current_schema.schema['dependencies'].each do |property,dependency_value|
            if data.has_key?(property)
              if dependency_value.is_a?(String)
                if !data.has_key?(dependency_value)
                  message = "The property '#{build_fragment(fragments)}' has a property '#{property}' that depends on a missing property '#{dependency_value}'"
                  validation_error(message, fragments, current_schema, options[:record_errors])
                end
              elsif dependency_value.is_a?(Array)
                dependency_value.each do |value|
                  if !data.has_key?(value)
                    message = "The property '#{build_fragment(fragments)}' has a property '#{property}' that depends on a missing property '#{value}'"
                    validation_error(message, fragments, current_schema, options[:record_errors])
                  end
                end
              else
                schema = JSON::Schema.new(dependency_value,current_schema.uri,validator)
                schema.validate(data, fragments, options)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
json-schema-1.0.3 lib/json-schema/attributes/dependencies.rb
json-schema-1.0.2 lib/json-schema/attributes/dependencies.rb
seomoz-json-schema-1.0.1 lib/json-schema/attributes/dependencies.rb
json-schema-1.0.1 lib/json-schema/attributes/dependencies.rb
json-schema-1.0.0 lib/json-schema/attributes/dependencies.rb