@@ -61,6 +61,38 @@ def app; SimpleApiWithApiVersion end
61
61
end
62
62
end
63
63
64
+ context "mounting in a versioned api" do
65
+ before ( :all ) do
66
+ class SimpleApiToMountInVersionedApi < Grape ::API
67
+ desc 'this gets something'
68
+ get '/something' do
69
+ { :bla => 'something' }
70
+ end
71
+ end
72
+
73
+ class SimpleApiWithVersionInPath < Grape ::API
74
+ version 'v1' , :using => :path
75
+
76
+ mount SimpleApiToMountInVersionedApi
77
+ add_swagger_documentation
78
+ end
79
+ end
80
+
81
+ def app ; SimpleApiWithVersionInPath end
82
+
83
+ it "should get the documentation on a versioned path /v1/swagger_doc" do
84
+ get '/v1/swagger_doc'
85
+ last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :operations=>[], :apis=>[{:path=>\" /v1/swagger_doc/something.{format}\" }, {:path=>\" /v1/swagger_doc/swagger_doc.{format}\" }]}"
86
+ end
87
+
88
+ it "should get the resource specific documentation on a versioned path /v1/swagger_doc/something" do
89
+ get '/v1/swagger_doc/something'
90
+ last_response . status . should == 200
91
+ end
92
+
93
+ end
94
+
95
+
64
96
context "overruling hiding the documentation paths" do
65
97
before ( :all ) do
66
98
class HideDocumentationPathMountedApi < Grape ::API
@@ -80,7 +112,7 @@ def app; SimpleApiWithHiddenDocumentation end
80
112
81
113
it "it doesn't show the documentation path on /swagger_doc" do
82
114
get '/swagger_doc'
83
- last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :operations=>[], :apis=>[{:path=>\" /swagger_doc/something.{format}\" }]}"
115
+ last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :operations=>[], :apis=>[{:path=>\" /swagger_doc/something.{format}\" }]}"
84
116
end
85
117
end
86
118
@@ -143,27 +175,27 @@ def app; SimpleApiWithMarkdown end
143
175
last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :resourcePath=>\" \" , :apis=>[{:path=>\" /something.{format}\" , :operations=>[{:notes=>\" <p><em>test</em></p>\\ n\" , :summary=>\" this gets something\" , :nickname=>\" GET-something---format-\" , :httpMethod=>\" GET\" , :parameters=>[]}]}]}"
144
176
end
145
177
end
146
-
178
+
147
179
context "versioned API" do
148
180
before ( :all ) do
149
181
class VersionedMountedApi < Grape ::API
150
182
prefix 'api'
151
183
version 'v1'
152
-
184
+
153
185
desc 'this gets something'
154
186
get '/something' do
155
187
{ :bla => 'something' }
156
188
end
157
189
end
158
-
190
+
159
191
class SimpleApiWithVersion < Grape ::API
160
192
mount VersionedMountedApi
161
193
add_swagger_documentation :api_version => "v1"
162
194
end
163
195
end
164
-
196
+
165
197
def app ; SimpleApiWithVersion end
166
-
198
+
167
199
it "parses version and places it in the path" do
168
200
get '/swagger_doc/api'
169
201
last_response . body . should == "{:apiVersion=>\" v1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :resourcePath=>\" \" , :apis=>[{:path=>\" /api/v1/something.{format}\" , :operations=>[{:notes=>nil, :summary=>\" this gets something\" , :nickname=>\" GET-api--version-something---format-\" , :httpMethod=>\" GET\" , :parameters=>[]}]}]}"
0 commit comments