Skip to content

Commit 605e21b

Browse files
authored
Merge pull request #545 from bmdelaune/custom-format-error
Improve :failed_attribute value for custom formats
2 parents 8aad70f + 6119d49 commit 605e21b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/json-schema/attributes/formats/custom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def validate(current_schema, data, fragments, processor, _validator, options = {
1313
@validation_proc.call data
1414
rescue JSON::Schema::CustomFormatError => e
1515
message = "The property '#{self.class.build_fragment(fragments)}' #{e.message}"
16-
self.class.validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
16+
self.class.validation_error(processor, message, fragments, current_schema, self.class, options[:record_errors])
1717
end
1818
end
1919
end

test/custom_format_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def test_format_validation
9696
assert_equal(1, errors.count)
9797
assert_match(%r{The property '#/a' must be 42 in schema}, errors.first, "#{prefix} records format error")
9898

99+
errors_as_objects = JSON::Validator.fully_validate(schema, data, errors_as_objects: true)
100+
101+
assert_match('CustomFormat', errors_as_objects.first[:failed_attribute], "#{prefix} tags failed attribute")
102+
99103
data['a'] = 23
100104
errors = JSON::Validator.fully_validate(schema, data)
101105

0 commit comments

Comments
 (0)