Skip to content

Commit 90eab19

Browse files
committed
Merge pull request #1401 from xhh/ruby-base-url-slashes
Ruby client: remove trailing slashes from base_url
2 parents 8a2c34b + e0dfc1b commit 90eab19

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

modules/swagger-codegen/src/main/resources/ruby/configuration.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module {{moduleName}}
138138
end
139139

140140
def base_url
141-
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}"
141+
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
142142
URI.encode(url)
143143
end
144144

samples/client/petstore/ruby/lib/petstore/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def base_path=(base_path)
138138
end
139139

140140
def base_url
141-
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}"
141+
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
142142
URI.encode(url)
143143
end
144144

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
describe Petstore::Configuration do
4+
let(:config) { Petstore::Configuration.instance }
5+
6+
before(:each) do
7+
Petstore.configure do |c|
8+
c.host = 'petstore.swagger.io'
9+
c.base_path = 'v2'
10+
end
11+
end
12+
13+
describe '#base_url' do
14+
it 'should have the default value' do
15+
config.base_url.should == 'http://petstore.swagger.io/v2'
16+
end
17+
18+
it 'should remove trailing slashes' do
19+
[nil, '', '/', '//'].each do |base_path|
20+
config.base_path = base_path
21+
config.base_url.should == 'http://petstore.swagger.io'
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)