Skip to content
Open
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
2 changes: 1 addition & 1 deletion connexion/apis/flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def console_ui_home(self):
:return:
"""
openapi_json_route_name = "{blueprint}.{prefix}_openapi_json"
escaped = flask_utils.flaskify_endpoint(self.base_path)
escaped = flask_utils.flaskify_endpoint(self.base_path) or "/"
openapi_json_route_name = openapi_json_route_name.format(
blueprint=escaped, prefix=escaped
)
Expand Down
10 changes: 10 additions & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ def test_swagger_ui(simple_api_spec_dir, spec):
assert b"swagger-ui-config.json" not in swagger_ui.data


@pytest.mark.parametrize("spec", ["basepath-slash.yaml", "servers-url-slash.yaml"])
def test_swagger_ui_for_basepath_slash(simple_api_spec_dir, spec):
"""Verify the Swagger UI is returned when spec has trivial base path."""
app = App(__name__, port=5001, specification_dir=simple_api_spec_dir, debug=True)
app.add_api(spec)
app_client = app.app.test_client()
swagger_ui = app_client.get("/ui/") # type: flask.Response
assert swagger_ui.status_code == 200


@pytest.mark.parametrize("spec", SPECS)
def test_swagger_ui_with_config(simple_api_spec_dir, spec):
swagger_ui_config = {"displayOperationId": True}
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/simple/servers-url-slash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.0
info:
title: "Test servers/url == /"
version: '1.0'

servers:
- url: /

paths:
'/greeting/{name}':
post:
summary: Generate greeting
description: Generates a greeting message.
operationId: fakeapi.hello.post_greeting
responses:
'200':
description: greeting response
content:
'application/json':
schema:
type: object
parameters:
- name: name
in: path
description: Name of the person to greet.
required: true
schema:
type: string
4 changes: 4 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def test_api_base_path_slash():
assert api.blueprint.name == "/"
assert api.blueprint.url_prefix == ""

api2 = FlaskApi(TEST_FOLDER / "fixtures/simple/servers-url-slash.yaml")
assert api2.blueprint.name == "/"
assert api2.blueprint.url_prefix == ""


def test_template():
api1 = FlaskApi(
Expand Down