File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'grape-swagger/entity'
6
+
7
+ module API
8
+ module V1
9
+ class Welcome < Grape ::API
10
+ desc 'Greets user' do
11
+ detail 'This is the root api and it will greet user on accessing'
12
+ end
13
+ get "/" do
14
+ {
15
+ data : [
16
+ { message : "Welcome to notes app" }
17
+ ]
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ module API
25
+ module V1
26
+ class Base < Grape ::API
27
+ version :v1 , using : :path
28
+
29
+ mount Welcome
30
+ end
31
+ end
32
+ end
33
+
34
+ module API
35
+ class Base < Grape ::API
36
+ format :json
37
+ prefix :api
38
+
39
+ mount V1 ::Base
40
+
41
+ add_swagger_documentation hide_documentation_path : true ,
42
+ version : "V1" ,
43
+ info : {
44
+ title : 'User notes app' ,
45
+ description : 'Demo app for user notes'
46
+ }
47
+ end
48
+ end
49
+
50
+ describe 'swagger is not detecting mounted rack app' do
51
+ let ( :app ) { API ::Base }
52
+
53
+ context 'when a rack app is mounted under API::Base' do
54
+
55
+ context 'when api/v1/ is called' do
56
+ subject do
57
+ get '/api/v1'
58
+ JSON . parse ( last_response . body )
59
+ end
60
+
61
+ it 'checks if the response is correct' do
62
+ expect ( subject ) . to eq ( { "data" => [ { "message" => "Welcome to notes app" } ] } )
63
+ end
64
+ end
65
+
66
+ context 'when api/swagger_doc is called' do
67
+ subject do
68
+ get '/api/swagger_doc'
69
+ JSON . parse ( last_response . body )
70
+ end
71
+
72
+ it 'checks if the swagger documentation is properly generated' do
73
+ expect ( subject [ "paths" ] ) . to_not be_nil
74
+ end
75
+ end
76
+ end
77
+ end
You can’t perform that action at this time.
0 commit comments