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

Adding swagger documentation for multiple Grape APIs in single Rails app #28

Closed
jhecking opened this issue Mar 5, 2013 · 10 comments
Closed

Comments

@jhecking
Copy link
Contributor

jhecking commented Mar 5, 2013

In our Rails app we are mounting two separate Grape APIs, e.g. /api/partner/v1 and /api/clients/v1. Now when I call add_swagger_documentation for each of these APIs, two separate swagger_doc entry points are mounted correctly. However querying these two entry points returns the same API documentation. E.g. querying /api/partner/v1/swagger_doc.json returns the documentation for API::Partner but querying /api/clients/v1/swagger_doc.json also returns the documentation for API::Partner.

I've been doing some debugging on this issue and it seems that the @@target_class class variable points to the same API class in the get @@mount_path definition:

get @@mount_path do
  Rails.logger.debug("XXXX self class: #{self.class}, #{self.class.object_id}")
  header['Access-Control-Allow-Origin'] = '*'
  header['Access-Control-Request-Method'] = '*'
  routes = @@target_class::combined_routes
  Rails.logger.debug("XXXX routes for #{@@target_class}: #{routes}")

This is despite the fact that two separate documentation classes get created with separate class variable. Somehow these class variables get merged into a single new instance of the Grape::Endpoint class. Here is what I see in the logs:

Started GET "/api/client/v1/client_api_docs.json" for 127.0.0.1 at 2013-03-06 01:38:24 +0800
XXXX self class: Grape::Endpoint, 70097079507800
XXXX routes for API::Client: {"search"=>[version=v1, method=GET, path=/:version/search(.:format)]}

Started GET "/api/partner/v1/partner_api_docs.json" for 127.0.0.1 at 2013-03-06 01:19:14 +0800
XXXX self class: Grape::Endpoint, 70097079507800
XXXX routes for API::Client: {"client_api_docs"=>[version=v1, method=GET, path=/:version/client_api_docs(.:format), version=v1, method=GET, path=/:version/client_api_docs/:name(.:format)], "search"=>[version=v1, method=GET, path=/:version/search(.:format)]}

Maybe this data shouldn't be stored in class variables?

@adambair
Copy link

adambair commented May 3, 2013

Having the same issue. Consider the scenario where you'd want to mount multiple api versions within grape (mount Twitter::APIv1, mount Twitter::APIv2)

@berlincount
Copy link

same issue here ...

@reiz
Copy link

reiz commented Jun 30, 2013

Dito! I have the same issue.

@timgluz
Copy link
Contributor

timgluz commented Jul 3, 2013

I just got it work; I'm currently cleaning up code and working on live demo. But meanwhile you can checkout code and your's feedback is welcome, specially from decent Ruby devs, because i'm quite newbie in Ruby.

@timgluz
Copy link
Contributor

timgluz commented Jul 9, 2013

I have now livedemos - Versioneye uses grape-swagger to add Swagger's documention for different versions( v1,v2 ) on same server.

As you can notice settings are api-specific - you can add version without changing old versions:

  • version1 - our first api, used default settings
  • version2 - newest version, different url-structure, hides extensions

@dblock
Copy link
Member

dblock commented Jul 14, 2014

This has been fixed in #57.

@dblock dblock closed this as completed Jul 14, 2014
@wyattisimo
Copy link

As far as I can tell, this does not work with grape version cascading. For example, if I mount my v1 endpoints like so:

module API::V1
  class Root < Grape::API
    version ['v2', 'v1'], using: :path

    mount API::V1::Places
    mount API::V1::Users

    add_swagger_documentation api_version: 'v1', mount_path: '/docs'
  end
end

...and mount my v2 endpoints like so:

module API::V2
  class Root < Grape::API
    version 'v2', using: :path, cascade: true

    mount API::V2::Users

    add_swagger_documentation api_version: 'v2', mount_path: '/docs'
  end
end

...then the v2 docs do not include any of the endpoints defined in API::V1::Places, despite the fact that grape correctly cascades to those endpoints from v2.

Am I missing something?

@dblock
Copy link
Member

dblock commented Aug 29, 2014

I don't think you're missing anything, can you reopen an issue specifically for this?

@gessgallardo
Copy link

this get fixed in other version or the ticket is still open?

@dblock
Copy link
Member

dblock commented Sep 21, 2016

#146 is still open, is that what you're asking @gessgallardo ?

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

8 participants