serverless-openapi-documenter 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- package/README.md +27 -27
- package/package.json +1 -1
- package/src/definitionGenerator.js +18 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: "[BUG]"
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: JaredCE
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Steps to reproduce the behavior:
|
|
15
|
+
```
|
|
16
|
+
serverless.yml
|
|
17
|
+
...
|
|
18
|
+
```
|
|
19
|
+
**Expected behavior**
|
|
20
|
+
A clear and concise description of what you expected to happen.
|
|
21
|
+
|
|
22
|
+
**Desktop (please complete the following information):**
|
|
23
|
+
- Serverless version: [e.g. 2.73.3]
|
|
24
|
+
- serverless-openapi-documenter version [e.g. 0.0.2]
|
|
25
|
+
|
|
26
|
+
**Additional context**
|
|
27
|
+
Add any other context about the problem here.
|
package/README.md
CHANGED
|
@@ -4,19 +4,39 @@ This will generate an OpenAPI V3 (up to v3.0.3) file for you from your serverles
|
|
|
4
4
|
|
|
5
5
|
Originally based off of: https://github.com/temando/serverless-openapi-documentation
|
|
6
6
|
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
This plugin works for Serverless 2.x and up.
|
|
10
|
+
|
|
11
|
+
To add this plugin to your package.json:
|
|
12
|
+
|
|
13
|
+
**Using npm:**
|
|
14
|
+
```bash
|
|
15
|
+
npm install --save-dev serverless-openapi-documenter
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Next you need to add the plugin to the `plugins` section of your `serverless.yml` file.
|
|
19
|
+
|
|
20
|
+
```yml
|
|
21
|
+
plugins:
|
|
22
|
+
- serverless-openapi-documenter
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> Note: Add this plugin _after_ `serverless-offline` to prevent issues with `String.replaceAll` being overridden incorrectly.
|
|
26
|
+
|
|
7
27
|
## Adding documentation to serverless
|
|
8
28
|
|
|
9
29
|
To Run: `serverless openapi generate -o openapi.json -f json -a 3.0.3 -p postman.json`
|
|
10
30
|
|
|
11
31
|
Options:
|
|
12
32
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
```
|
|
34
|
+
--output -o What filename the OpenAPI documentation should output under. Default: openapi.json
|
|
35
|
+
--format -f Whether to output the OpenAPI documentation as json or yaml. Default: json
|
|
36
|
+
--indent -i File indentation in spaces. Default: 2
|
|
37
|
+
--openApiVersion -a OpenAPI version to generate for. Default: 3.0.0
|
|
38
|
+
--postmanCollection -p Will generate a postman collection (from the generated openAPI documentation), in json only, if passed in. Default postman.json
|
|
39
|
+
```
|
|
20
40
|
|
|
21
41
|
### OpenAPI Mapping
|
|
22
42
|
|
|
@@ -312,26 +332,6 @@ requestHeaders:
|
|
|
312
332
|
|
|
313
333
|
Please view the example [serverless.yml](test/serverless\ 2/serverless.yml).
|
|
314
334
|
|
|
315
|
-
## Install
|
|
316
|
-
|
|
317
|
-
This plugin works for Serverless 2.x and up.
|
|
318
|
-
|
|
319
|
-
To add this plugin to your package.json:
|
|
320
|
-
|
|
321
|
-
**Using npm:**
|
|
322
|
-
```bash
|
|
323
|
-
npm install serverless-openapi-documenter --save-dev
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
Next you need to add the plugin to the `plugins` section of your `serverless.yml` file.
|
|
327
|
-
|
|
328
|
-
```yml
|
|
329
|
-
plugins:
|
|
330
|
-
- serverless-openapi-documenter
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
> Note: Add this plugin _after_ `serverless-offline` to prevent issues with `String.replaceAll` being overridden incorrectly.
|
|
334
|
-
|
|
335
335
|
## License
|
|
336
336
|
|
|
337
337
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverless-openapi-documenter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": ["serverless", "serverless2", "serverless3", "openAPI", "openAPIv3", "openAPI3", "PostmanCollections", "Postman-Collections"],
|
|
@@ -22,6 +22,8 @@ class DefinitionGenerator {
|
|
|
22
22
|
this.openAPI = {
|
|
23
23
|
openapi: this.version,
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
this.operationIds = []
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
parse() {
|
|
@@ -50,14 +52,28 @@ class DefinitionGenerator {
|
|
|
50
52
|
if (event?.http?.documentation || event?.httpApi?.documentation) {
|
|
51
53
|
const documentation = event.http.documentation || event.httpApi.documentation
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
let opId
|
|
56
|
+
if (this.operationIds.includes(httpFunction.functionInfo.name) === false) {
|
|
57
|
+
opId = httpFunction.functionInfo.name
|
|
58
|
+
this.operationIds.push(opId)
|
|
59
|
+
} else {
|
|
60
|
+
opId = `${httpFunction.functionInfo.name}-${uuid()}`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const path = this.createOperationObject(event.http.method || event.httpApi.method, documentation, opId)
|
|
54
64
|
if (httpFunction.functionInfo?.summary)
|
|
55
65
|
path.summary = httpFunction.functionInfo.summary
|
|
56
66
|
|
|
57
67
|
if (httpFunction.functionInfo?.description)
|
|
58
68
|
path.description = httpFunction.functionInfo.description
|
|
59
69
|
|
|
60
|
-
|
|
70
|
+
let slashPath = event.http.path
|
|
71
|
+
const pathStart = new RegExp(/^\//, 'g')
|
|
72
|
+
if (pathStart.test(slashPath) === false) {
|
|
73
|
+
slashPath = `/${event.http.path}`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Object.assign(paths, {[slashPath]: path})
|
|
61
77
|
}
|
|
62
78
|
}
|
|
63
79
|
}
|