Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stex opened this issue Feb 26, 2019 · 1 comment · May be fixed by #10
Open

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

stex opened this issue Feb 26, 2019 · 1 comment · May be fixed by #10

Comments

@stex
Copy link

stex commented Feb 26, 2019

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!

@stex
Copy link
Author

stex commented Mar 4, 2019

Altering the following method in spec/support/examples/builder_initialization.rb will also produce the error, causing the test to fail:

def settings_for(obj)
  settings = obj.object :settings, null: true
  settings.string :email
  settings
end

Edit: I gave up trying to fix it myself... I am clearly not smart enough to fully understand this gem. A few comments and a little less magic would certainly help, but I'm sure someone else will be able to solve this easily.

@Haniyya Haniyya linked a pull request Mar 5, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant