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

swagger is not detecting mounted rack app

Open bhaskarshankarling opened this issue 7 years ago • 5 comments

Code

require "bundler/setup"
Bundler.require

require 'grape-swagger/entity'

module API
  module V1
    class Welcome < Grape::API
      desc 'Greets user' do
        detail 'This is the root api and it will greet user on accessing'
      end
      get "/" do
        { 
          data: [
            { message: "Welcome to notes app" }
          ]
        }
      end
    end
  end
end

module API
  module V1
    class Base < Grape::API
      version :v1, using: :path

      mount Welcome
    end
  end
end

module API
  class Base < Grape::API
    format :json
    prefix :api

    mount V1::Base

    add_swagger_documentation hide_documentation_path: true,
                              version: "V1",
                              info: {
                                title: 'User notes app',
                                description: 'Demo app for user notes'
                              }
  end
end

Gemfile

# frozen_string_literal: true

source "https://rubygems.org"

ruby '2.5.3'

gem 'grape', '~> 1.2', '>= 1.2.1'

gem 'grape-swagger-entity'

gem 'rake'

gem 'rack-cors'

gem 'pry'

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    activesupport (5.2.1.1)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    axiom-types (0.1.1)
      descendants_tracker (~> 0.0.4)
      ice_nine (~> 0.11.0)
      thread_safe (~> 0.3, >= 0.3.1)
    builder (3.2.3)
    coderay (1.1.2)
    coercible (1.0.0)
      descendants_tracker (~> 0.0.1)
    concurrent-ruby (1.1.3)
    descendants_tracker (0.0.4)
      thread_safe (~> 0.3, >= 0.3.1)
    equalizer (0.0.11)
    grape (1.2.1)
      activesupport
      builder
      mustermann-grape (~> 1.0.0)
      rack (>= 1.3.0)
      rack-accept
      virtus (>= 1.0.0)
    grape-entity (0.7.1)
      activesupport (>= 4.0)
      multi_json (>= 1.3.2)
    grape-swagger (0.32.0)
      grape (>= 0.16.2)
    grape-swagger-entity (0.3.1)
      grape-entity (>= 0.5.0)
      grape-swagger (>= 0.31.0)
    i18n (1.1.1)
      concurrent-ruby (~> 1.0)
    ice_nine (0.11.2)
    method_source (0.9.2)
    minitest (5.11.3)
    multi_json (1.13.1)
    mustermann (1.0.3)
    mustermann-grape (1.0.0)
      mustermann (~> 1.0.0)
    pry (0.12.2)
      coderay (~> 1.1.0)
      method_source (~> 0.9.0)
    rack (2.0.6)
    rack-accept (0.4.5)
      rack (>= 0.4)
    rack-cors (1.0.2)
    rake (12.3.1)
    thread_safe (0.3.6)
    tzinfo (1.2.5)
      thread_safe (~> 0.1)
    virtus (1.0.5)
      axiom-types (~> 0.1)
      coercible (~> 1.0)
      descendants_tracker (~> 0.0, >= 0.0.3)
      equalizer (~> 0.0, >= 0.0.9)

PLATFORMS
  ruby

DEPENDENCIES
  grape (~> 1.2, >= 1.2.1)
  grape-swagger-entity
  pry
  rack-cors
  rake

RUBY VERSION
   ruby 2.5.3p105

BUNDLED WITH
   1.17.1

I am trying to generate swagger compatible documentation and I got the link at http://localhost:9292/api/swagger_doc. The /api is because of prefix :api in API::Base module. I am getting the below response from the link.

{
  "info": {
    "title": "User notes app",
    "description": "Demo app for user notes",
    "version": "0.0.1"
  },
  "swagger": "2.0",
  "produces": [
    "application/json"
  ],
  "host": "localhost:9292"
}

As we can see there is no documentation generated for the endpoint defined inside API::V1::Welcome class. Please let me know if I am doing anything wrong over here.

bhaskarshankarling avatar Dec 05 '18 13:12 bhaskarshankarling

I don't see anything wrong, this should work. I would turn it into a spec next in this repo and PR.

dblock avatar Dec 05 '18 14:12 dblock

Ok Thanks you. I am new to swagger ecosystem. If possible can you point me towards any blog/article for setting up swagger UI at local development machine.

bhaskarshankarling avatar Dec 06 '18 07:12 bhaskarshankarling

I don't think you need swagger UI, but see CONTRIBUTING in this project for how to contribute in general

If you do want actual swagger UI, the way I do it is to run ngrok locally that proxies to my localhost server and use https://petstore.swagger.io

dblock avatar Dec 06 '18 19:12 dblock

Regarding adding spec for this case, should I just go on and create a new pull request and this spec in a new file?. I want to contribute to this gem. I am new to open source contribution. Please point me in the right direction.

bhaskarshankarling avatar Dec 07 '18 17:12 bhaskarshankarling

Regarding adding spec for this case, should I just go on and create a new pull request and this spec in a new file?. I want to contribute to this gem. I am new to open source contribution. Please point me in the right direction.

Yes! We welcome failing specs in a pull request so that another person can fix the bugs, too.

dblock avatar Dec 07 '18 17:12 dblock