Skip to content

Commit

Permalink
Add custom JSONSchemer::Schema#inspect
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davishmcclurg committed Jul 25, 2023
1 parent 2106527 commit b5b26d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/json_schemer/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ def error(formatted_instance_location:, **)
"instance at #{formatted_instance_location} does not match schema"
end

def inspect
"#<#{self.class.name} @value=#{@value.inspect} @parent=#{@parent.inspect} @keyword=#{@keyword.inspect}>"
end

private

def parse
Expand Down
6 changes: 6 additions & 0 deletions test/json_schemer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ def test_draft7_additional_items_error
assert_equal('array items at root do not match `additionalItems` schema', OutputHelper.as_json!(schemer.validate([1, 2])).dig('errors', 1, 'error'))
end

def test_inspect
output = JSONSchemer.openapi31_document.inspect
assert_includes(output, 'JSONSchemer::Schema')
assert_includes(output, '@value=')
end

def test_it_allows_validating_schemas
valid_draft7_schema = { '$ref' => '#/definitions/~1some~1%7Bid%7D' }
invalid_draft7_schema = { '$ref' => '#/definitions/~1some~1{id}' }
Expand Down

0 comments on commit b5b26d6

Please sign in to comment.