Skip to content

Commit 1d443d5

Browse files
committed
Refactor to aws-serverless-swagger-ui
1 parent 7db7b7e commit 1d443d5

File tree

5 files changed

+151
-330
lines changed

5 files changed

+151
-330
lines changed

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@ on:
88
types: [created]
99

1010
jobs:
11-
build:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v1
16-
with:
17-
node-version: 12
18-
- run: npm ci
19-
- run: npm test
20-
2111
publish-npm:
22-
needs: build
2312
runs-on: ubuntu-latest
2413
steps:
2514
- uses: actions/checkout@v2
@@ -30,18 +19,5 @@ jobs:
3019
- run: npm ci
3120
- run: npm publish
3221
env:
33-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
22+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
3423

35-
publish-gpr:
36-
needs: build
37-
runs-on: ubuntu-latest
38-
steps:
39-
- uses: actions/checkout@v2
40-
- uses: actions/setup-node@v1
41-
with:
42-
node-version: 12
43-
registry-url: https://npm.pkg.github.com/
44-
- run: npm ci
45-
- run: npm publish
46-
env:
47-
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

README.md

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,54 @@
1-
# Swagger UI AWS API Gateway
1+
# AWS Serverless Swagger UI
22

3-
This module is branched from [swagger-ui-express](https://www.npmjs.com/package/swagger-ui-express). It allows you to serve auto-generated [swagger-ui](https://swagger.io/tools/swagger-ui/) generated API docs from the AWS API Gateway. It uses Lambda functions to generate the API docs based on a `swagger.json` or `swagger.yaml` file. The result is living documentation for your API hosted on your AWS API Gateway.
3+
This module allows you to serve auto-generated [swagger-ui](https://swagger.io/tools/swagger-ui/) API docs
4+
from the AWS API Gateway.
5+
It uses Lambda functions to generate the API docs based on a swagger/open-api yaml file.
6+
The result is living documentation for your API hosted on your AWS API Gateway.
47

5-
Swagger version is pulled from npm module swagger-ui-dist. Please use a lock file or specify the version of swagger-ui-dist you want to ensure it is consistent across environments.
8+
Initially based upon [swagger-ui-aws-apigateway](https://github.com/klauslochmann/swagger-ui-aws-apigateway),
9+
this version focus on :
10+
* simplify the code base.
11+
* speed up rendering
12+
* update code with ES6 syntax including async handler.
13+
* reduce the number of HTTP requests.
14+
* accept any filename in `.yaml` for the definition, not only `interface.yaml`.
15+
* allow the path to be whatever you want, not limited to `/api-docs` (see [Restrictions](#restrictions)).
16+
* fix media files rendering in base64.
617

7-
You may be also interested in:
8-
9-
* [swagger tools](https://github.com/swagger-api): Various tools, including swagger editor, swagger code gen etc.
10-
11-
## Usage
12-
13-
Install using npm:
18+
## Install
1419

1520
```bash
16-
$ npm install swagger-ui-aws-apigateway
21+
npm install aws-serverless-swagger-ui
1722
```
1823

24+
## Usage
25+
1926
Configure your API Gateway:
20-
* Create a resource of type "proxy resource"
27+
* Create a resource which will serve your sagger UI (ex: /docs)
28+
* Create a resource of type "proxy resource" (ex: /docs/{proxy+})
2129
* Create a method ANY
2230
* Create a lambda function of type "LAMBDA_PROXY"
2331

2432
In your AWS lambda function, include this package as follows:
2533

2634
```javascript
27-
const swaggerUi = require('swagger-ui-aws-apigateway');
28-
const fs = require('fs');
29-
30-
// read your yaml file and initialize
31-
const swaggerDocument = fs.readFileSync('./interface/service_interface.yaml');
32-
var swaggerHandler = swaggerUi.setup(swaggerDocument);
35+
const swaggerUi = require('aws-serverless-swagger-ui');
36+
const swaggerHandler = swaggerUi.setup('swagger.yaml');
3337

34-
// call the swagger api doc in your handler
35-
36-
exports.handler = (event, context, callback) => {
37-
38-
if (event.path.includes("/api-docs")) {
39-
console.log("Got request to the api docs.");
40-
swaggerHandler(event, context, callback);
41-
return;
42-
}
43-
44-
// ... your other code ...
4538

39+
exports.handler = async (event, context, callback) => {
40+
return (await swaggerHandler)(event, context, callback);
4641
}
4742
```
4843

49-
## Restrictions
44+
Once deployed, access your swagger ui at : `https://your-api-gateway-endpoint/your-mount-path/index.html`
45+
5046

51-
Currently the path in the url must be named "api-docs".
47+
## Restrictions
5248

53-
## Requirements
49+
Because API Gateway doesn't match the root folder with {proxy+} definition, your default URL should contain index.html.
50+
We suggest creating a mock integration on your main folder to return a 301. (ex: /docs => 301 => /docs/index.html)
5451

55-
* Node v0.10.32 or above
52+
## Logs
5653

54+
You can print some logs by setting the Environment Variable `DEBUG`

0 commit comments

Comments
 (0)