module JSI
module Schema::Validation::Dependencies
def internal_validate_dependencies(result_builder)
if keyword?('dependencies')
value = schema_content['dependencies']
if value.respond_to?(:to_hash)
value.each_pair do |property_name, dependency|
if dependency.respond_to?(:to_ary)
if result_builder.instance.respond_to?(:to_hash) && result_builder.instance.key?(property_name)
missing_required = dependency.reject { |name| result_builder.instance.key?(name) }
result_builder.validate(
missing_required.empty?,
'instance object does not contain all dependent required property names specified by `dependencies` value',
keyword: 'dependencies',
)
end
else
if result_builder.instance.respond_to?(:to_hash) && result_builder.instance.key?(property_name)
dependency_result = result_builder.inplace_subschema_validate(['dependencies', property_name])
result_builder.validate(
dependency_result.valid?,
'instance object is not valid against the schema corresponding to a matched property name specified by `dependencies` value',
keyword: 'dependencies',
results: [dependency_result],
)
end
end
end
else
result_builder.schema_error('`dependencies` is not an object', 'dependencies')
end
end
end
end
end