diff --git a/connexion/middleware/swagger_ui.py b/connexion/middleware/swagger_ui.py index a9bded0fe..65052b797 100644 --- a/connexion/middleware/swagger_ui.py +++ b/connexion/middleware/swagger_ui.py @@ -151,12 +151,12 @@ async def redirect(request): url += "/" return RedirectResponse(url=url) - self.router.add_route(methods=["GET"], path=console_ui_path, endpoint=redirect) + self.router.add_route(methods=["GET"], path=console_ui_path or "/", endpoint=redirect) # this route will match and get a permission error when trying to # serve index.html, so we add the redirect above. self.router.mount( - path=console_ui_path, + path=console_ui_path or "/", app=StaticFiles(directory=str(self.options.swagger_ui_template_dir)), name="swagger_ui_static", ) diff --git a/tests/api/conftest.py b/tests/api/conftest.py index bfde3ed03..4dac36a4b 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -30,7 +30,7 @@ def swagger_ui_app(app_class): app_class=app_class, spec_file=OPENAPI3_SPEC, validate_responses=True, - swagger_ui_options=SwaggerUIOptions(spec_path="/spec.json"), + swagger_ui_options=SwaggerUIOptions(spec_path="/spec.json", swagger_ui_path="/"), )