0

I'm using the grape-swagger gem and I'm being unable to get a Grape-based API properly described in Swagger. Using: grape (0.11.0) and grape-swagger (0.10.1)

When I enable the Swagger json listing I get this output listing all endpoints but not the methods contained in each endpoint.

My output:

{
  "apiVersion": "v0",
  "swaggerVersion": "1.2",
  "produces": [
    "application/json"
  ],
  "apis": [
    {
    "path": "/version.{format}",
    "description": "Operations about versions"
    },
    {
    "path": "/ping.{format}",
    "description": "Operations about pings"
    },
    {
    "path": "/users.{format}",
    "description": "Operations about users"
    },
    {
    "path": "/company.{format}",
    "description": "Operations about companies"
    },
    {
    "path": "/merchants.{format}",
    "description": "Operations about merchants"
    }
  ],
  "info": {}
}

I've also added CORS Allowance in config.ru like this:

require 'rack/cors'
use Rack::Cors do
  allow do
    origins '*'
    resource '*',
      headers: :any,
      methods: [:get, :post, :put, :delete, :options]
  end
end

Any clue on how to get methods for each endpoint listed inside?

Jorge Diaz
  • 2,503
  • 1
  • 14
  • 15

1 Answers1

1

That's just not how Swagger 1.2 works.

Assuming you get the above JSON at /api-docs, try opening /api-docs/version.json for example to see the operations for version. Of course, if it's not hosted under /api-docs, just replace that part with whichever path segment is actually used.

Ron
  • 14,160
  • 3
  • 52
  • 39
  • For some stupid reason I was totally expecting a unified response JSON file. Now everything makes sense and swagger-ui works perfectly using this output. Thanks! – Jorge Diaz May 19 '15 at 15:57
  • 1
    For what it's worth, Swagger 2.0 is indeed a single file. No idea when grape-swagger would release support for it, but you should be on the lookout for it. – Ron May 19 '15 at 16:03
  • Good to know that of Swagger 2.0. My guess is that the multiple-file approach comes from the WSDL days, which is like that, and can somehow be called the XML antecesor of Swagger. – Jorge Diaz Oct 14 '15 at 04:18