Skip to content

Commit

Permalink
Move Swagger UI to /static/index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
nadove-ucsc committed Nov 21, 2024
1 parent d786f9f commit bff2348
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
16 changes: 16 additions & 0 deletions lambdas/indexer/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
},
"paths": {
"/": {
"get": {
"summary": "A redirect to the Swagger UI for interactive use of this REST API",
"tags": [
"Auxiliary"
],
"responses": {
"301": {
"description": "A redirect to the Swagger UI"
},
"504": {
"description": "\nRequest timed out. When handling this response, clients\nshould wait the number of seconds specified in the\n`Retry-After` header and then retry the request.\n"
}
}
}
},
"/static/index.html": {
"get": {
"summary": "A Swagger UI for interactive use of this REST API",
"tags": [
Expand Down
16 changes: 16 additions & 0 deletions lambdas/service/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
],
"paths": {
"/": {
"get": {
"summary": "A redirect to the Swagger UI for interactive use of this REST API",
"tags": [
"Auxiliary"
],
"responses": {
"301": {
"description": "A redirect to the Swagger UI"
},
"504": {
"description": "\nRequest timed out. When handling this response, clients\nshould wait the number of seconds specified in the\n`Retry-After` header and then retry the request.\n"
}
}
}
},
"/static/index.html": {
"get": {
"summary": "A Swagger UI for interactive use of this REST API",
"tags": [
Expand Down
25 changes: 24 additions & 1 deletion src/azul/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,13 @@ def catalog(self) -> str:
def _controller(self, controller_cls: type[C], **kwargs) -> C:
return controller_cls(app=self, **kwargs)

def swagger_redirect(self) -> Response:
return Response(status_code=301,
body='',
headers={'Location': str(self.self_url.set(path='static/index.html'))})

def swagger_ui(self) -> Response:
swagger_ui_template = self.load_static_resource('swagger', 'swagger-ui.html.template.mustache')
swagger_ui_template = self.load_static_resource('swagger', 'index.html.template.mustache')
base_url = self.base_url
redirect_url = furl(base_url).add(path='oauth2_redirect')
deployment_url = furl(base_url).add(path='openapi')
Expand Down Expand Up @@ -677,6 +682,24 @@ def default_routes(self):
@self.route(
'/',
interactive=False,
method_spec={
'summary': 'A redirect to the Swagger UI for interactive use of this REST API',
'tags': ['Auxiliary'],
'responses': {
'301': {
'description': 'A redirect to the Swagger UI'
}
}
}
)
def swagger_redirect():
return Response(status_code=301,
body='',
headers={'Location': str(self.base_url.set(path='static/index.html'))})

@self.route(
'/static/index.html',
interactive=False,
cache_control=self._http_cache_for(60),
cors=False,
method_spec={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" href="static/swagger-ui.css" crossorigin="anonymous">
<link rel="stylesheet" href="./swagger-ui.css" crossorigin="anonymous">
<style>
html
{
Expand All @@ -28,8 +28,8 @@

<body>
<div id="swagger-ui"></div>
<script src="static/swagger-ui-bundle.js"></script>
<script src="static/swagger-ui-standalone-preset.js"></script>
<script src="./swagger-ui-bundle.js"></script>
<script src="./swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function() {
// Adapted from https://github.com/swagger-api/swagger-ui/issues/3725#issuecomment-334899276
Expand Down

0 comments on commit bff2348

Please sign in to comment.