Skip to content

Extending objects with null: true causes a StackLevelTooDeep exception #9

@stex

Description

@stex

Hi again 😅

today I ran into a problem when using the functionality implemented in #8: If I build a schema by extending an existing object instead of nesting everything and assigning null: true, a StackLevelTooDeep exception will be thrown.

As this seems to only happen with null as attribute which is internally translated to an any_of, I would suspect that it has something to do with this.

I will investigate a bit further myself, but maybe you have an idea what exactly is causing this instantly.
I find myself having a few problems following the gem's working due to its architecture.


The following is the smallest example I could produce that still causes the error.
It will print the stacktrace once its size reaches 3000.

#!/usr/bin/env ruby

require 'json/schema_builder'

trace_func_proc = proc do |event, file, line, id, binding, classname|
  if event == 'call' && caller.length > 3000
    puts caller
    exit(1)
  end
end

set_trace_func(trace_func_proc)

class SchemaStack
  include JSON::SchemaBuilder

  def schema
    obj = object :bar, null: true
    obj.string :baz
    obj
  end
end

SchemaStack.new.schema.as_json

The repeating portion seems to be:

/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/entity.rb:141:in `extract_types'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/object.rb:30:in `extract_types'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/object.rb:35:in `reinitialize'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/attribute.rb:16:in `block in attribute'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/entity.rb:142:in `extract_types'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/entity.rb:46:in `initialize'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/dsl.rb:11:in `new'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/dsl.rb:11:in `entity'
/Users/stex/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/json-schema_builder-0.8.2/lib/json/schema_builder/dsl.rb:45:in `block (2 levels) in register'

Thanks a lot in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions