Open
Conversation
Thanks to @thrau for the tip
There was a problem hiding this comment.
PR Summary
This pull request introduces Swagger UI integration for LocalStack, providing an interactive API documentation interface for internal developer endpoints.
- Added new endpoint
http://localhost.localstack.cloud:4566/_localstack/swaggerinlocalstack-core/localstack/plugins.pyto serve Swagger UI - Implemented OpenAPI spec merging functionality in new file
localstack-core/localstack/utils/openapi.py - Created
SwaggerUIApiclass in new filelocalstack-core/localstack/utils/swagger.pyto handle Swagger UI routing and rendering - Added HTML template for Swagger UI in
localstack-core/localstack/templates/index.html - Updated
pyproject.tomlto include new static files and templates in package data
6 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings
Comment on lines
+38
to
+43
| def _merge_openapi_specs(specs: list[dict[str, Any]]) -> dict[str, Any]: | ||
| """ | ||
| Merge a list of OpenAPI specs into a single specification. | ||
| :param specs: a list of OpenAPI specs loaded in a dictionary | ||
| :return: the dictionary of a merged spec. | ||
| """ |
There was a problem hiding this comment.
style: Consider adding type hints for the return value in the function signature
Comment on lines
+82
to
+83
| # In case of an error while merging the spec, we return the first collected one. | ||
| return specs[0].spec |
There was a problem hiding this comment.
logic: Returning the first spec on error might lead to unexpected behavior. Consider raising a custom exception instead
Comment on lines
+17
to
+22
| def server_swagger_ui(self, _request): | ||
| oas_path = os.path.join(os.path.dirname(__file__), "..", "templates") | ||
| env = Environment(loader=FileSystemLoader(oas_path)) | ||
| template = env.get_template("index.html") | ||
| rendered_template = template.render() | ||
| return Response(rendered_template, content_type="text/html") |
There was a problem hiding this comment.
style: Consider caching the rendered template to improve performance for subsequent requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We recently introduced OpenAPI specs for different LocalStack packages (localstack and localstack.pro.core at the moment).
These specs document all the internal developer endpoints we serve in LocalStack.
To allow users to navigate those specs, we want to serve the SwaggerUI directly within LocalStack.
Changes