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

fix(event-handler): swagger schema respects api stage #3796

Merged
merged 2 commits into from
Feb 19, 2024
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"]
Loading