Skip to content

Commit

Permalink
Specify spec as absolute path reference instead of absolute URI
Browse files Browse the repository at this point in the history
This should resolve any issues one might have with serving Swagger UI
behind a reverse proxy where protocols or ports change,
without any additional configuration.

Signed-off-by: Ievgen Popovych <[email protected]>
  • Loading branch information
Jmennius authored and zupo committed Apr 24, 2024
1 parent c5f4dbb commit 652cdc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyramid_openapi3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def explorer_view(request: Request) -> Response:
template = Template(f.read())
html = template.safe_substitute(
ui_version=ui_version,
spec_url=request.route_url(settings[apiname]["spec_route_name"]),
spec_url=request.route_path(settings[apiname]["spec_route_name"]),
)
return Response(html)

Expand Down
8 changes: 4 additions & 4 deletions pyramid_openapi3/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ def test_add_multiple_explorer_views() -> None:
)
response = view(request=DummyRequest(config=config), context=None)
assert b"<title>Swagger UI</title>" in response.body
assert b"http://example.com/foo/openapi.yaml" in response.body
assert b'url: "/foo/openapi.yaml"' in response.body

request = config.registry.queryUtility(IRouteRequest, name="bar_api_explorer")
view = config.registry.adapters.registered(
(IViewClassifier, request, Interface), IView, name=""
)
response = view(request=DummyRequest(config=config), context=None)
assert b"<title>Swagger UI</title>" in response.body
assert b"http://example.com/bar/openapi.yaml" in response.body
assert b'url: "/bar/openapi.yaml"' in response.body


def test_add_multiple_explorer_views_using_directory() -> None:
Expand Down Expand Up @@ -398,15 +398,15 @@ def test_add_multiple_explorer_views_using_directory() -> None:
)
response = view(request=DummyRequest(config=config), context=None)
assert b"<title>Swagger UI</title>" in response.body
assert b"http://example.com/foo.yaml" in response.body
assert b'url: "/foo.yaml"' in response.body

request = config.registry.queryUtility(IRouteRequest, name="bar_api_explorer")
view = config.registry.adapters.registered(
(IViewClassifier, request, Interface), IView, name=""
)
response = view(request=DummyRequest(config=config), context=None)
assert b"<title>Swagger UI</title>" in response.body
assert b"http://example.com/bar.yaml" in response.body
assert b'url: "/bar.yaml"' in response.body


def test_explorer_view_missing_spec() -> None:
Expand Down

0 comments on commit 652cdc1

Please sign in to comment.