Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 463 forks source link

protected method `logger' called for Apipie::Extractor::Writer:Class (NoMethodError) #681

Open respire opened 4 years ago

respire commented 4 years ago

Environment:

Step to reproduce

append this line in test_helper.rb

Apipie.record('params')

and then run functional tests

Expected

write doc without error

Actual

an exception raised

protected method `logger' called for Apipie::Extractor::Writer:Class (NoMethodError)

/usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor/writer.rb:204:in `logger': protected method `logger' called for Apipie::Extractor::Writer:Class (NoMethodError)

Full log

5 tests, 24 assertions, 0 failures, 0 errors, 0 skips
Updating auto-generated documentation
Traceback (most recent call last):
    15: from -e:1:in `<main>'
    14: from /usr/local/rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    13: from /usr/local/rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    12: from /usr/local/rvm/gems/ruby-2.6.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    11: from /usr/local/rvm/gems/ruby-2.6.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    10: from /usr/local/rvm/gems/ruby-2.6.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
     9: from /usr/local/rvm/gems/ruby-2.6.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
     8: from /usr/local/rvm/gems/ruby-2.6.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
     7: from /usr/local/rvm/gems/ruby-2.6.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
     6: from /usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor.rb:185:in `block in <main>'
     5: from /usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor.rb:56:in `finish'
     4: from /usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor.rb:80:in `write_docs'
     3: from /usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor/writer.rb:83:in `write_docs'
     2: from /usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor/writer.rb:83:in `each'
     1: from /usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor/writer.rb:85:in `block in write_docs'
/usr/local/rvm/gems/ruby-2.6.1/gems/apipie-rails-0.5.17/lib/apipie/extractor/writer.rb:204:in `logger': protected method `logger' called for Apipie::Extractor::Writer:Class (NoMethodError)
ghost commented 4 years ago

@respire I was able to reproduce this bug when I switched to using versioned apis. It looks like adding versions with different base_urls caused it: Reproduces bug:

  config.api_base_url = ""
  config.api_base_url["unstable"] = ""
  config.api_base_url["v1"] = "/api/v1"
  config.default_version = "v1"

Fix:

  config.api_base_url = ""
  config.api_base_url["unstable"] = ""
  config.api_base_url["v1"] = ""
  config.default_version = "v1"

I also had to add back the prefix /api/v1 to all my routes in my "v1" controllers. Bad: api :GET, '/stuff', 'List of Stuff' Good: api :GET, '/api/v1/stuff', 'List of Stuff'

It seems like multiple versions/base_urls are not well supported.

The real fix would be to fix the writer.rb class in apipie and move the lines 66-68 above the protected line. Though I think the root cause is that Apipie is not properly handling the base url correctly and thus causing the warnings in the first place.