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

swagger is not detecting mounted rack app #730

Open
bhaskarshankarling opened this issue Dec 5, 2018 · 5 comments
Open

swagger is not detecting mounted rack app #730

bhaskarshankarling opened this issue Dec 5, 2018 · 5 comments
Labels

Comments

@bhaskarshankarling
Copy link

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.

@dblock
Copy link
Member

dblock commented Dec 5, 2018

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

@dblock dblock added the bug? label Dec 5, 2018
@bhaskarshankarling
Copy link
Author

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.

@dblock
Copy link
Member

dblock commented Dec 6, 2018

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

@bhaskarshankarling
Copy link
Author

bhaskarshankarling commented Dec 7, 2018

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.

@dblock
Copy link
Member

dblock commented Dec 7, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants