Skip to content

Commit 77a1218

Browse files
committed
Use URL scheme in default base path
1 parent 51a4916 commit 77a1218

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/grape-swagger.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.setup(options)
7070
{
7171
apiVersion: api_version,
7272
swaggerVersion: "1.1",
73-
basePath: base_path || "http://#{env['HTTP_HOST']}",
73+
basePath: base_path || "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}",
7474
operations:[],
7575
apis: routes_array
7676
}
@@ -102,7 +102,7 @@ def self.setup(options)
102102
{
103103
apiVersion: api_version,
104104
swaggerVersion: "1.1",
105-
basePath: base_path || "http://#{env['HTTP_HOST']}",
105+
basePath: base_path || "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}",
106106
resourcePath: "",
107107
apis: routes_array
108108
}

spec/non_default_api_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,31 @@ def app; SimpleApiWithVersion end
170170
end
171171
end
172172

173+
context "protected API" do
174+
before(:all) do
175+
class ProtectedApi < Grape::API
176+
desc 'this gets something'
177+
get '/something' do
178+
{:bla => 'something'}
179+
end
180+
end
181+
182+
class SimpleApiWithProtection < Grape::API
183+
mount ProtectedApi
184+
add_swagger_documentation
185+
end
186+
end
187+
188+
def app; SimpleApiWithProtection; end
173189

190+
it "should use https schema in mount point" do
191+
get '/swagger_doc', {}, 'rack.url_scheme' => 'https'
192+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"https://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
193+
end
194+
195+
it "should use https schema in endpoint doc" do
196+
get '/swagger_doc/something', {}, 'rack.url_scheme' => 'https'
197+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"https://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>\"GET-something---format-\", :httpMethod=>\"GET\", :parameters=>[]}]}]}"
198+
end
199+
end
174200
end

0 commit comments

Comments
 (0)