diff --git a/connexion/spec.py b/connexion/spec.py index be5d653e5..9f4603953 100644 --- a/connexion/spec.py +++ b/connexion/spec.py @@ -269,7 +269,7 @@ def base_path(self): @base_path.setter def base_path(self, base_path): - base_path = canonical_base_path(base_path) + base_path = "/" + canonical_base_path(base_path).lstrip("/") self._raw_spec["basePath"] = base_path self._spec["basePath"] = base_path diff --git a/tests/api/conftest.py b/tests/api/conftest.py index bfde3ed03..e428c4426 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -24,11 +24,22 @@ def simple_openapi_app(app_class): @pytest.fixture(scope="session") -def swagger_ui_app(app_class): +def swagger_ui_app(spec, app_class): return build_app_from_fixture( "simple", app_class=app_class, - spec_file=OPENAPI3_SPEC, + spec_file=spec, + validate_responses=True, + swagger_ui_options=SwaggerUIOptions(spec_path="/spec.json"), + ) + + +@pytest.fixture(scope="session") +def swagger_ui_basepath_app(app_class): + return build_app_from_fixture( + "simple", + app_class=app_class, + spec_file="basepath-slash.yaml", validate_responses=True, swagger_ui_options=SwaggerUIOptions(spec_path="/spec.json"), ) diff --git a/tests/api/test_swagger_ui.py b/tests/api/test_swagger_ui.py index 1d787c65a..1d40e6381 100644 --- a/tests/api/test_swagger_ui.py +++ b/tests/api/test_swagger_ui.py @@ -1,4 +1,17 @@ +from connexion.spec import Specification + + def test_simple(swagger_ui_app): app_client = swagger_ui_app.test_client() response = app_client.get("/v1.0/spec.json") assert response.status_code == 200 + # Load the spec into Connexion to validate it + Specification.from_dict(response.json()) + + +def test_basepath(swagger_ui_basepath_app): + app_client = swagger_ui_basepath_app.test_client() + response = app_client.get("/spec.json") + assert response.status_code == 200 + # Load the spec into Connexion to validate it + Specification.from_dict(response.json())