Skip to content

Commit ce223cf

Browse files
committed
Ensure basePath is always a path
1 parent b4bca0b commit ce223cf

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Changelog
66
Current
77
-------
88

9-
- Nothing yet
9+
- Ensure `basePath` is always a path
1010

1111
0.12.1 (2018-09-28)
1212
-------------------

flask_restplus/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def base_path(self):
469469
470470
:rtype: str
471471
'''
472-
return url_for(self.endpoint('root'))
472+
return url_for(self.endpoint('root'), _external=False)
473473

474474
@cached_property
475475
def __schema__(self):

tests/test_swagger.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,26 @@ def test_specs_endpoint_no_host(self, app, client):
152152

153153
data = client.get_specs('')
154154
assert 'host' not in data
155+
assert data['basePath'] == '/'
155156

157+
@pytest.mark.options(server_name='api.restplus.org')
156158
def test_specs_endpoint_host(self, app, client):
157-
app.config['SERVER_NAME'] = 'api.restplus.org'
159+
# app.config['SERVER_NAME'] = 'api.restplus.org'
158160
restplus.Api(app)
159161

160162
data = client.get_specs('')
161163
assert data['host'] == 'api.restplus.org'
164+
assert data['basePath'] == '/'
165+
166+
@pytest.mark.options(server_name='api.restplus.org')
167+
def test_specs_endpoint_host_with_url_prefix(self, app, client):
168+
blueprint = Blueprint('api', __name__, url_prefix='/api/1')
169+
restplus.Api(blueprint)
170+
app.register_blueprint(blueprint)
171+
172+
data = client.get_specs('/api/1')
173+
assert data['host'] == 'api.restplus.org'
174+
assert data['basePath'] == '/api/1'
162175

163176
@pytest.mark.options(server_name='restplus.org')
164177
def test_specs_endpoint_host_and_subdomain(self, app, client):
@@ -168,6 +181,7 @@ def test_specs_endpoint_host_and_subdomain(self, app, client):
168181

169182
data = client.get_specs(base_url='http://api.restplus.org')
170183
assert data['host'] == 'api.restplus.org'
184+
assert data['basePath'] == '/'
171185

172186
def test_specs_endpoint_tags_short(self, app, client):
173187
restplus.Api(app, tags=['tag-1', 'tag-2', 'tag-3'])

0 commit comments

Comments
 (0)