Skip to content

Commit a4bccc2

Browse files
committed
Add custom JSONSchemer::Schema#inspect
The default `inspect` method hangs for some large schemas (eg, `JSONSchemer.openapi31_document`) for some reason. This seems like something that should be fixed in Ruby generally, but it is what it is.
1 parent 03fdc8e commit a4bccc2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/json_schemer/schema.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def error(formatted_instance_location:, **options)
234234
end
235235
end
236236

237+
def inspect
238+
"#<#{self.class.name} @value=#{@value.inspect} @parent=#{@parent.inspect} @keyword=#{@keyword.inspect}>"
239+
end
240+
237241
private
238242

239243
def parse

test/json_schemer_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ def test_draft7_additional_items_error
289289
assert_equal('array items at root do not match `additionalItems` schema', OutputHelper.as_json!(schemer.validate([1, 2])).dig('errors', 1, 'error'))
290290
end
291291

292+
def test_inspect
293+
output = JSONSchemer.openapi31_document.inspect
294+
assert_includes(output, 'JSONSchemer::Schema')
295+
assert_includes(output, '@value=')
296+
end
297+
292298
def test_it_allows_validating_schemas
293299
valid_draft7_schema = { '$ref' => '#/definitions/~1some~1%7Bid%7D' }
294300
invalid_draft7_schema = { '$ref' => '#/definitions/~1some~1{id}' }

0 commit comments

Comments
 (0)