Skip to content

Commit 5b5f6ac

Browse files
committed
fix(event_handler): correct URL for OpenAPI spec in Swagger UI
1 parent f40ad68 commit 5b5f6ac

File tree

3 files changed

+1
-32
lines changed

3 files changed

+1
-32
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

-1
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,6 @@ def swagger_handler():
19581958

19591959
body = generate_swagger_html(
19601960
escaped_spec,
1961-
f"{base_path}{path}",
19621961
swagger_js,
19631962
swagger_css,
19641963
swagger_base_url,

aws_lambda_powertools/event_handler/openapi/swagger_ui/html.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
def generate_swagger_html(
77
spec: str,
8-
path: str,
98
swagger_js: str,
109
swagger_css: str,
1110
swagger_base_url: str,
@@ -19,8 +18,6 @@ def generate_swagger_html(
1918
----------
2019
spec: str
2120
The OpenAPI spec
22-
path: str
23-
The path to the Swagger documentation
2421
swagger_js: str
2522
Swagger UI JavaScript source code or URL
2623
swagger_css: str
@@ -94,7 +91,7 @@ def generate_swagger_html(
9491
}}
9592
9693
var ui = SwaggerUIBundle(swaggerUIOptions)
97-
ui.specActions.updateUrl('{path}?format=json');
94+
ui.specActions.updateUrl(currentUrl.pathname + "?format=json");
9895
{oauth2_content}
9996
</script>
10097
</html>

tests/functional/event_handler/_pydantic/test_openapi_swagger.py

-27
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,6 @@ def test_openapi_swagger_json_view_with_custom_path():
9191
assert "OpenAPI JSON View" in result["body"]
9292

9393

94-
def test_openapi_swagger_with_rest_api_default_stage():
95-
app = APIGatewayRestResolver(enable_validation=True)
96-
app.enable_swagger()
97-
98-
event = load_event("apiGatewayProxyEvent.json")
99-
event["path"] = "/swagger"
100-
event["requestContext"]["stage"] = "$default"
101-
102-
result = app(event, {})
103-
assert result["statusCode"] == 200
104-
assert "ui.specActions.updateUrl('/swagger?format=json')" in result["body"]
105-
106-
107-
def test_openapi_swagger_with_rest_api_stage():
108-
app = APIGatewayRestResolver(enable_validation=True)
109-
app.enable_swagger()
110-
111-
event = load_event("apiGatewayProxyEvent.json")
112-
event["path"] = "/swagger"
113-
event["requestContext"]["stage"] = "prod"
114-
event["requestContext"]["path"] = "/prod/swagger"
115-
116-
result = app(event, {})
117-
assert result["statusCode"] == 200
118-
assert "ui.specActions.updateUrl('/prod/swagger?format=json')" in result["body"]
119-
120-
12194
def test_openapi_swagger_with_persist_authorization():
12295
app = APIGatewayRestResolver(enable_validation=True)
12396
app.enable_swagger(persist_authorization=True)

0 commit comments

Comments
 (0)