Skip to content
Merged
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
8 changes: 7 additions & 1 deletion aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,13 @@ def swagger_handler():
body=escaped_spec,
)

body = generate_swagger_html(escaped_spec, path, swagger_js, swagger_css, swagger_base_url)
body = generate_swagger_html(
escaped_spec,
f"{base_path}{path}",
swagger_js,
swagger_css,
swagger_base_url,
)

return Response(
status_code=200,
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/event_handler/test_openapi_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,30 @@ def test_openapi_swagger_json_view_with_custom_path():
assert result["multiValueHeaders"]["Content-Type"] == ["application/json"]
assert isinstance(json.loads(result["body"]), Dict)
assert "OpenAPI JSON View" in result["body"]


def test_openapi_swagger_with_rest_api_default_stage():
app = APIGatewayRestResolver(enable_validation=True)
app.enable_swagger()

event = load_event("apiGatewayProxyEvent.json")
event["path"] = "/swagger"
event["requestContext"]["stage"] = "$default"

result = app(event, {})
assert result["statusCode"] == 200
assert "ui.specActions.updateUrl('/swagger?format=json')" in result["body"]


def test_openapi_swagger_with_rest_api_stage():
app = APIGatewayRestResolver(enable_validation=True)
app.enable_swagger()

event = load_event("apiGatewayProxyEvent.json")
event["path"] = "/swagger"
event["requestContext"]["stage"] = "prod"
event["requestContext"]["path"] = "/prod/swagger"

result = app(event, {})
assert result["statusCode"] == 200
assert "ui.specActions.updateUrl('/prod/swagger?format=json')" in result["body"]