Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if base_path is relative make it absolute using request.base_uri #69

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ def strip_heredoc(string)
end

def parse_base_path(base_path, request)
(base_path.is_a?(Proc) ? base_path.call(request) : base_path) || request.base_url
if base_path.is_a?(Proc)
base_path.call(request)
elsif base_path.is_a?(String)
URI(base_path).relative? ? URI.join(request.base_url, base_path).to_s : base_path
else
request.base_url
end
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions spec/non_default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ def app; SimpleApiWithProcBasePath end
end
end

context "relative base_path" do
before :all do

class RelativeBasePathMountedApi < Grape::API
desc 'This gets something.'
get '/something' do
{ bla: 'something' }
end
end

class SimpleApiWithRelativeBasePath < Grape::API
mount RelativeBasePathMountedApi
add_swagger_documentation base_path: "/some_value"
end
end

def app; SimpleApiWithRelativeBasePath end

it "retrieves the given base-path on /swagger_doc" do
get '/swagger_doc.json'
JSON.parse(last_response.body)["basePath"].should == "http://example.org/some_value"
end

it "retrieves the same given base-path for mounted-api" do
get '/swagger_doc/something.json'
JSON.parse(last_response.body)["basePath"].should == "http://example.org/some_value"
end
end

context "overriding the version" do
before :all do

Expand Down