Open
Description
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.