Skip to content

fix(event_handler): correct URL for OpenAPI spec in Swagger UI #4930

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

Merged
merged 2 commits into from
Aug 13, 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
1 change: 0 additions & 1 deletion aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,6 @@ def swagger_handler():

body = generate_swagger_html(
escaped_spec,
f"{base_path}{path}",
swagger_js,
swagger_css,
swagger_base_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

def generate_swagger_html(
spec: str,
path: str,
swagger_js: str,
swagger_css: str,
swagger_base_url: str,
Expand All @@ -19,8 +18,6 @@ def generate_swagger_html(
----------
spec: str
The OpenAPI spec
path: str
The path to the Swagger documentation
swagger_js: str
Swagger UI JavaScript source code or URL
swagger_css: str
Expand Down Expand Up @@ -94,7 +91,7 @@ def generate_swagger_html(
}}

var ui = SwaggerUIBundle(swaggerUIOptions)
ui.specActions.updateUrl('{path}?format=json');
ui.specActions.updateUrl(currentUrl.pathname + "?format=json");
{oauth2_content}
</script>
</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,6 @@ def test_openapi_swagger_json_view_with_custom_path():
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"]


def test_openapi_swagger_with_persist_authorization():
app = APIGatewayRestResolver(enable_validation=True)
app.enable_swagger(persist_authorization=True)
Expand Down