Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serving swagger-ui as index #1852

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions connexion/middleware/swagger_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather change the way the path is stripped above.

console_ui_path = self.options.swagger_ui_path.strip().rstrip("/") + "/"

and removing the leading "/" from the suffixes we add everywhere.


# 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",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="/"),
)


Expand Down
Loading