1
+ require 'spec_helper'
2
+
3
+ describe "overruling the defaults for the api documentation generation" do
4
+
5
+ class MountedApi < Grape ::API
6
+ desc 'this gets something'
7
+ get '/something' do
8
+ { :bla => 'something' }
9
+ end
10
+ end
11
+
12
+
13
+ context "overruling the basepath" do
14
+ class SimpleApiWithBasePath < Grape ::API
15
+ NON_DEFAULT_BASE_PATH = "http://www.breakcoregivesmewood.com"
16
+
17
+ mount MountedApi
18
+ add_swagger_documentation :base_path => NON_DEFAULT_BASE_PATH
19
+ end
20
+
21
+ subject { SimpleApiWithBasePath . new }
22
+ def app ; subject end
23
+
24
+ it "retrieves the given base-path on /swagger_doc" do
25
+ get '/swagger_doc'
26
+ last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" #{ SimpleApiWithBasePath ::NON_DEFAULT_BASE_PATH } \" , :operations=>[], :apis=>[{:path=>\" /swagger_doc/mountedapi.{format}\" }, {:path=>\" /swagger_doc/swagger_doc.{format}\" }]}"
27
+ end
28
+
29
+ it "retrieves the same given base-path for mounted-api" do
30
+ Random . stub ( :rand ) { 0 }
31
+ get '/swagger_doc/mountedapi'
32
+ last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" #{ SimpleApiWithBasePath ::NON_DEFAULT_BASE_PATH } \" , :resourcePath=>\" \" , :apis=>[{:path=>\" /something.{format}\" , :operations=>[{:notes=>nil, :summary=>\" this gets something\" , :nickname=>0, :httpMethod=>\" GET\" , :parameters=>[]}]}]}"
33
+ end
34
+ end
35
+
36
+ context "overruling the basepath" do
37
+ class SimpleApiWithAPiVersion < Grape ::API
38
+ API_VERSION = "101"
39
+
40
+ mount MountedApi
41
+ add_swagger_documentation :api_version => API_VERSION
42
+ end
43
+
44
+ subject { SimpleApiWithAPiVersion . new }
45
+ def app ; subject end
46
+
47
+ it "retrieves the given base-path on /swagger_doc" do
48
+ get '/swagger_doc'
49
+ last_response . body . should == "{:apiVersion=>\" #{ SimpleApiWithAPiVersion ::API_VERSION } \" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :operations=>[], :apis=>[{:path=>\" /swagger_doc/mountedapi.{format}\" }, {:path=>\" /swagger_doc/swagger_doc.{format}\" }]}"
50
+ end
51
+
52
+ it "retrieves the same given base-path for mounted-api" do
53
+ Random . stub ( :rand ) { 0 }
54
+ get '/swagger_doc/mountedapi'
55
+ last_response . body . should == "{:apiVersion=>\" #{ SimpleApiWithAPiVersion ::API_VERSION } \" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :resourcePath=>\" \" , :apis=>[{:path=>\" /something.{format}\" , :operations=>[{:notes=>nil, :summary=>\" this gets something\" , :nickname=>0, :httpMethod=>\" GET\" , :parameters=>[]}]}]}"
56
+ end
57
+ end
58
+
59
+ context "overruling the mount-path" do
60
+ class SimpleApiWithDifferentMount < Grape ::API
61
+ MOUNT_PATH = "api_doc"
62
+
63
+ mount MountedApi
64
+ add_swagger_documentation :mount_path => MOUNT_PATH
65
+ end
66
+
67
+ subject { SimpleApiWithDifferentMount . new }
68
+ def app ; subject end
69
+
70
+ it "retrieves the given base-path on /swagger_doc" do
71
+ get '/api_doc'
72
+ last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :operations=>[], :apis=>[{:path=>\" /swagger_doc/mountedapi.{format}\" }, {:path=>\" /swagger_doc/swagger_doc.{format}\" }]}"
73
+ end
74
+
75
+ it "retrieves the same given base-path for mounted-api" do
76
+ Random . stub ( :rand ) { 0 }
77
+ get '/api_doc/mountedapi'
78
+ last_response . body . should == "{:apiVersion=>\" 0.1\" , :swaggerVersion=>\" 1.1\" , :basePath=>\" http://example.org\" , :resourcePath=>\" \" , :apis=>[{:path=>\" /something.{format}\" , :operations=>[{:notes=>nil, :summary=>\" this gets something\" , :nickname=>0, :httpMethod=>\" GET\" , :parameters=>[]}]}]}"
79
+ end
80
+
81
+ it "does not respond to swagger_doc" do
82
+ get '/swagger_doc'
83
+ last_response . status . should be == 404
84
+ end
85
+ end
86
+
87
+
88
+ end
0 commit comments