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

Any way to include apipie into my engine and have the docs available in the final app? #127

Open
jmoses opened this issue Jun 6, 2013 · 8 comments

Comments

@jmoses
Copy link
Contributor

jmoses commented Jun 6, 2013

I get a namespace error when I visit the mounted apipie url in my app.

engine's routes:

Core::Engine.routes.draw do
  apipie
  # snip
end

application's routes:

Rails.application.routes.draw do
  root to: "game#index"

  mount Core::Engine => "/core"
end

Resulting Routes:

root  /     game#index
core  /core Core::Engine

Routes for Core::Engine:
apipie_apipie GET  /apipie(/:version)(/:resource)(/:method)(.:format) core/apipie/apipies#index {:version=>/[^\/]+/}
# snip

Error:

Routing Error
uninitialized constant Core::Apipie

@jmoses
Copy link
Contributor Author

jmoses commented Jun 7, 2013

If I subclass the Apipie::ApipiesController in my engine, it starts to work at least, but it doesn't find any controllers with documentation.

@iNecas
Copy link
Member

iNecas commented Jun 10, 2013

You might try setting api_controllers_matcher to match the controllers in your engine. There might be a problem that it will override the settings from the host app, as this case was not considered yet. At least we would know this way is possible, and we can add better support for this.

I will need to do something similar soon, so we can sync our approaches.

@jmoses
Copy link
Contributor Author

jmoses commented Jun 10, 2013

So, I may have got it to work.

  • include the apipie gem into your engine
  • setup the initializer in your engine (using the engine's root/path for controllers)
  • add the apipie routes call into your application (not the engine)

@jmoses
Copy link
Contributor Author

jmoses commented Jun 10, 2013

So, my next problem is that I allow the engine using app to modify fields on some of the core objects, which changes what my API documentation should show (ie: adding a "full_name" parameter to User). Ideally I'd be able to, in the initializer or something do:

Apipie.config do
  Core::UserController.modify_docs(:update) do
    param :user, Hash do
      param :full_name, String, desc: "Optional full name of the user"
    end
  end
end

I'm looking for maybe where to put it, but I'm in a mazy of twisty passages, all alike.

@jmoses
Copy link
Contributor Author

jmoses commented Jun 10, 2013

So, instance_evaling a block from with a Hash parameters block does what I was looking for, at least now. It's still icky.

param :user, Hash do
  instance_eval(&extra_documentation)
end

@gwbarrett
Copy link

I have a mountable engine that is packaged as a gem and then included in my main application; I want the API documentation for the mountable engine to be accessible in the main application. Is this issue now resolved? Are there any step-by-step instructions on working around it? Any guidance will be appreciated.

Thanks.

@playq-deployer
Copy link

My 3 steps in #127 (comment) still work for me.

@leobagua
Copy link

leobagua commented Oct 30, 2020

To anyone interested in a solution, following #127 (comment)

The name of my engine is AuthEngine, below follow my config:

# engines/auth_engine/initializers/apipie.rb
Apipie.configure do |config|
  config.app_name = "Auth"
  config.api_base_url = "/api/auth/"
  config.doc_base_url = "/docs/"
  config.api_routes = AuthEngine::Engine.routes
  config.api_controllers_matcher = "#{AuthEngine::Engine.root}/app/controllers/auth_engine/**/*.rb"
end

In the main Rails App

# config/routes.rb
Rails.application.routes.draw do
   apipie
end

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

No branches or pull requests

5 participants