grape-swagger icon indicating copy to clipboard operation
grape-swagger copied to clipboard

Dynamic namespace problem

Open mepatterson opened this issue 11 years ago • 3 comments
trafficstars

This is a weird one that I'm having trouble debugging. If I do this:

namespace ':color' do
  resource :toys do
    desc "Get a list of toys, scoped by color"
    get '' do
      @toys = Toy.where(color: params[:color])
      @toys
    end
  end
end

The intent is to have endpoints like /red/toys.json and /blue/toys.json

These work perfectly.

... but apparently Swagger/Grape-Swagger cannot document that endpoint.

GET /swagger_doc/orders.json returns []

If I put any other endpoints inside that same ':color' dynamic namespace, it won't document any of those either, unless I remove the GET '' endpoint, in which case it will document the others fine. If I change it to GET 'list' it will document that fine, too, but I'd rather have it as '/' because adding 'list' is redundant.

Am I doing something wrong, or is this a problem in Grape-Swagger?

mepatterson avatar Aug 08 '14 15:08 mepatterson

ok.... weird... so I got around this by adding a 'mount_path' config option to my add_swagger_documentation line... but I don't fully understand why this fixes things:

    add_swagger_documentation hide_documentation_path: true,
                              api_version: 'v1',
                              mount_path: "/docs/v1"

... if I change that mount_path to anything only 1-level deep (e.g. "/docs" or "/foobars") it blows up, but if I make it two or more levels deep, no problems.

Entirely possible that this is something to do with my fairly complex multi-version API mounted atop Rails...

mepatterson avatar Aug 08 '14 16:08 mepatterson

I think your latter theory is more viable, but try to build a simpler repro maybe?

dblock avatar Aug 08 '14 20:08 dblock

is it still an issue with the actual version?

LeFnord avatar Jan 13 '17 19:01 LeFnord